Use remainder instead of mask.  Performance impact should be negligible.