Remove an extra division

Currently, GHC does not merge `div` with `mod` by itself; `divMod` saves time.

Turn nested `if`s into `case`.