moved assignment of templateName to within file handling