small changed in the algorithm