Made the program more resistant to crashes caused by connects/disconnects