Didn't take into account whether a layer was required before removing active item. Fixed.