refactor if-chain to case statement