work on generation
Refactoring 3 stage generation.
New API.
Simplify code