Fix crashes related to character encoding