refactored code generation