Fix output in client mode and a bit of refactoring
Improve unit tests
Enable error recovery for TCP client