Simplified nonNegativeMod to match previous version