Added JSON support. Other small cleanups