Correct algorithm.