split template generator to separate function