fix 'dictionary changed size during iteration'