Use switch instead of ifs

For consistency with the rest of the toLevel function