Added switch to maintain index association while sorting.