More refactoring of code generator