avoid unnecessary JSON parsing on the client-side (also, make toJSON more obvious)
some minor cleanup, no semantic changes