main template refactor