templates refactoring