new version of the algorithm