corrected the sorting of IDs