refactoring stuff into a main generator class, useful for subtemplates