diff --git a/client-code/gui-orchestrator.py b/client-code/gui-orchestrator.py
index 117418351a0190751fea014c9bb7e6c1824d1b99..7b08d156f5e42b79c86c28afba95cc39363a9e9d 100644
--- a/client-code/gui-orchestrator.py
+++ b/client-code/gui-orchestrator.py
@@ -80,6 +80,10 @@ except serial.SerialException:
 
 # Function to process a clean exit from the GUI, destroying both windows (even if hidden)
 def leave():
+    try:
+        s.close()       # Close the serial port (if possible)
+    except serial.SerialException:
+        pass
     sys.exit(0) 
 
 # Establish the main window
@@ -253,4 +257,5 @@ window.after(0, custom_mainloop)
 try:
     window.mainloop()
 except KeyboardInterrupt:
+    s.close()
     sys.exit(0)
\ No newline at end of file