the algorithm