Fixed a couple of potential deadlock cases (note: need to delay disconnection logic to prevent this from ever occurring).