Replaced if-then-else with case