introduced function changeSelection, optimized implementation