move handshake functions into handshake.go