simplify and unify generator code