Modifed template.pl to be more generic.