Improve how cleaned images are removed after being downloaded

  • Add some tests
  • Make the process more reliable
  • Clean up the code