Trying to fix generator bug
Refactored as suggested in http://bit.ly/12WdV9X