Refactored connection code a bit and added a handshake response.