refactoring template loader