Added documentation and a function to tidy up json output