a solution for handshake problem