More refactoring with templates