Fix RuntimeError

RuntimeError: dictionary changed size during iteration