TemplateEngine related fixes