The sequential version of the algorithm works