indexes changed to reflect logic of coctail sort