fixed up tests, added toJSON method