Added support for generators

This change adds support for generators.