Alright, if I understand well, then it means that your data is not in the right order, the order that you want to use is the order given by the second or third field. The easiest might then be to start by sorting your AoA in accordance with the second field of each sub-array.