big refactoring of templates