Prevents dictionary changed size during iteration

Let's not pass the same dict object to a function that will potentially remove items from it, inside a for loop that is iterating over it, which will raise: RuntimeError: dictionary changed size during iteration.