More template refactoring (unfinished)