fixed allKArrays to be in lexicographic order