cleanup of handshake. untested.