added error handling for bad JSON