Cleanup and refactor of the json reading code