Fix and clean up client disconnection handling.