added doc comments and TemplateException