fix off-by-one