Please refactor the conditional logic repeated here and twice below into `setProto` itself.