Refactoring with templates