refactor rpc