Add second stage to the algorithm.

The final result is made up of two runs of the algorithm. It is still not
finished and needs more testing, but it shows promising results on N2DH-SIM.