Refactoring: pattern match on tuple instead of using if/else