avoid some "dictionary changed size during iteration" errors