working implementation of clockwise-renumber