codegen refactoring