Fix serious off-by-one issue