added better string escaping in encoder.