Convert case statement to if statement