Fix bug with resorting ids