Fixed misc bugs when the peer disconnects