Some of the basic algorithm.