Initial algorithm.