Yay, all building blocks are ready, so we can implement the main algorithm!