fix off-by-one that could lead to div by 0