Fixed cleanup that happens when duplicate images are detected. Got rid of some redunant code in the process