minor tweaks to character escaping