Modified algorithem