refactor code generation