more refactoring and TemplateWidget