Fix the algorithm