fix 'mod' to handle negative numbers right