some refactoring and added some generator function examples