Fixed bug that caused disconnection prematurely