Added better TCP connection management, fixed connection bugs.