Fixes crashes related to invalid UTF-8 characters