handling disconnection, fixes in protocol