add fix_json function to fix malformed json
slightly better error handling
add some documentation