parameterised function GetUrl to return URLS

using this function and removing obsolete code that created URLs
removing temporary variables
pseudocode to separate out call for total from loop