More codegen refactoring