start using generators, make refactoring