clean and organize the ids