M:  refactoring main template