Replace repeated if statements with switch statement