finished the first iteration of the algorithm