tidied up a bit of the code for JSON