Remove unused images and assign orphaned images