This pull request addresses an issue with the current implementation where items are being removed from a collection while iterating over it.
Iterating over a collection while removing items from it is not a recommended practice, as it can lead to unexpected behavior and bugs.
So we split the existing loop into two separate loops:
One for iterating over the collection and identifying items to be removed.
Another for actually removing those items from the collection.
This pull request addresses an issue with the current implementation where items are being removed from a collection while iterating over it.
Iterating over a collection while removing items from it is not a recommended practice, as it can lead to unexpected behavior and bugs.
So we split the existing loop into two separate loops: One for iterating over the collection and identifying items to be removed. Another for actually removing those items from the collection.