Added encoding handling