Implemented algorithm.