Delete unreferenced layers if an image is removed