Rough outline of the algorithm