corrected the algo.