templateReplacement function added (II part)