minor fixes to the 'toJSON' function