Extract rpc handling to separate classes