Moved GenerateHTMLwithTemplate here