sort by id if sort_elements is set