Added a check to see if the URL exists before comparing it to the previous attachment name.