Updated TemplateGenerator to perform better