Fix some character encoding bugs