retry function, url and encoding fixes