refactor protocol/handshake