refactored PatternMatcher class to provide better APIs