Added JSON schema validation & some refactoring