Refactor selected items code