refactoring on templates