improved the algorithm for search; previously selected data items can be restored after search is done