real mod function.