First version of algorithm repaired.