faster json encoding.  various improvements from other projects