Refactor: change client handshake from class to a free function.