Finally fixed the sorting and IDs