Handle disconnecting clients properly.

Also, add logging for connecting and disconnecting clients.