Fixed disconnection on main window close and improved serial connection management