rpc: code refactoring