Plugging memory leaks and rigging up the JSON