refactored RpcServer to make the flow clearer