Algorithms implementations.