Replaced generator with iterator