better encoding handling