Completed algorithm.