rewrite functions in generator (unfinished)