Fixed offset-by-one error