Modify the alg to find next cell

now I also cover the case in which there is no unvisite cell, this case should never happen but anyway