refactor PatternMatch