Refactored TCP protocol, fixing a problem with the client