better ring algorithm, fixing bugs