This code might be easier to understand with a switch statement instead.