It's generally a bad idea to remove items from a container while iterating through it. And fix the thread safe issue.