completed implementing Lubys algorithm