Fix and workaround encoding issues.