Refactor rpc handlers.