combined handshake code