fixed program flow, unindented tidied lines template.pl