unicode fixes

This replaces #4168 in order to add one commit to it.