added handshake code