Cleanup handshaking code