change if-else to case construct for more readability