Fix UTF-8 compatibility and escaping throughout