Fix to ensure schemaFiles are removed when schema is removed, and to fix some fatal errors in JSON creation