Fix to stop modifying the object we're iterating on to prevent a concurrent modification exception