Added code generation function