Corrected an error in the algorithm