Fix remove_incompatible items

Using cyordereddict revealed a bug: we were deleting items in the dictionary
in the process of iterating over it. That is a bad idea.