refactor code and replace if/else with case statement