sorting: cleaner inner loop for key indexed counting