Change a pack of ifs into a case statement