being called more than once. Also fix a problem where the URL was getting smashed in the environment by copying it to a temporary area before we jump up and down on it.
the code and split things into more logical groupings.