work on the algorithm