codegen refactor