c279d71
Avoid a modulo by zero range (tweight) could be 0 so check for that before getting the mod of r.