get rid of intermediate handshake_state variable