Comment out urldecode while loop
Rename encode%hex to urlencode