Fixed off-by-one error
Fixed test