Refactor to use lastSelected.
Refactor code into clearSelections().