refactored case statement