correct the algorithm