cleanup handshake code slightly.