refactoring on match functionality