Fixed patternMatch function so it does what it is supposed to, also reduced complexity to avoid having to rebuild the list