refactoring to split template parsing and records construction