Better reconnect logic

Better reconnect logic for the TCP client, and cleaned up the tests a bit, too.