Major changes to the algorithm