big refactoring of templates and models