refactor to use json schema and increase code coverage