recorrect the algorithm