Sorting: sorted_index_list(): BUGFIX

* Sorting: sorted_index_list(): BUGFIX:
  * apply optional mask at the end of the procedure, not at the beginning