Using a generator instead of an iterator; faster and cleaner.