Issue #8297 by tuj: Refactored way images are selected and deselected.