template refactored