Refactored match to be a little easier to test