rewrite algo for yield-generator