Add a save_json function and fix var names