Library: Watch out for duplicates while sorting