simplify code, return null if floats are Nan or Inf
rewrite escape_bytes to not write each byte individually