delete layers if image is removed

all layers are removed until an image is found in the hierarchy. this
does not take into account that multiple images can reference the same
layers.