Refactor the TemplateGenerator class