Meat of the algorithm

Work in progress