math: handle MOD operation better