Improve character escaping