[Naval, Vivi] Making sure that if an UnicodeError happens when replacing characters, we encode the text using UTF-8.