fixed some bugs found when actually using the toJSON method