Some codegen refactors