adding JSON support and cleaning code