Fix off-by-one issue