Updated to use to_json, much cleaner