Fix a bug that remove elements of an object currently being iterated