Fixes for logging outgoing messages.

* Restructured sending replies to server. 
* Fixed logging on outgoing messages. 
* Some formatting.