Use switch instead of ifs

For consistency with the rest of the toLevel function
Merge pull request #7 from lsiegert/master

Use switch instead of ifs
Thanks @lsiegert for improvement