Fix error when the collection is empty