Fix 'dictionary changed size during iteration'.