Algorithm implementations.