Valiant attempt at getting the basics of the algorithm working... but it doesn't work.
Several iterations on fixing the algorithm...