Fix sudden disconnection bug