Completely working version with old algorithm.

But some new data structures.