Refactored code generation