Updated TemplateGenerator.pm to perform better with large
number of DynamicFields.