Cleaning up code by using generator.
Fix syntax error
Fix syntax error.
Fix porting errors.
Merge branch 'generator'