Added handshake and messaging logic