fix closing connection on main window closing