refactored if to case statement