More rigorous handling of multibyte characters