algorithm corriged