refactor. use generator