Replace a bunch of ifs with a case