Refactor matching logic to a matcher class