Added loop to wait for handshake