modularized the generator code
merge