Refactored out the huge if - else if - else if statement.