Sort an array and maintain index association