refactoring pattern match