Replace case with if-then-else