some schema generation refactoring; its still ugly though...