redid the algorithm