Fixed a bug and name_count is now stored outside the script.

- name_count variable is now stored outside the script to prevent overwriting of an image.
- Fixed crash when len(url) = 0