refactored match function to predicate