Fix encoding handling