handle unicode better by decoding early and encoding late