modofied algo desceiption