Fix bug when a template references more than one template