made some improvements to handshake