Refactored getting and setting of selected item.