refactoring in a case statement