templateReplacement function completed