Handle non-utf-8 characters without crashing