Fixes to the algorithm
Fixes to the algorithm