Added a nested function to prevent code duplication.
Handle both top and bottom-of-list scenarios.
Added handling of case where all of the list items are selected.
Added handling of case where listItems are in the middle of rootList.