Added indexSort back in, but doesn't work correctly quite yet.