pure python 'mod M' calculation. Remove cruft