completed some of selection algorithm