Refactored connection management

handshake now returns a TCP connection