Remove unnecessary switch statement and DRY it out

Use an array and smart math to fix one of the most embarrassing bits of
code.