refactoring with simple pattern matching