changed the algorithm