fixed issues with connecting when exiting