* Finished second part of the algorithm