Fixed callback logic bugs in retrieveUrl and related functions