Fixed off-by-one error