Fix up toJSON to work correctly and remove unnecessary old code