generator refactor