Create PatternUtils, some refactoring