refactoring to use templates