template refactor