Major rewrite to support JSON is mostly done