Refactoring: matching generic templates in a separate method.