Add debug logging. Move logic of when to ask for a read out of the socket and into the client (fixes bug related to breaking tags when replying).