Correct some glaring errors in the schema and model generator.
various structural improvements