Updated logic in patternMatch, added a test for new function