revamped template, now allowing loops