toJSON bugfix, code cleanup
additional testing