Modified the implementation of the __iter__ method