Modified PatternMatcher to reduce memory usage