Fixes in modular arithmetic

The commit messages should be explanatory...