The gist of the algorithm