Add support for generators

Closes #23