Codegen

migrated useful code out of code generators into tools