Added code to clean up unused images from the cache