fixed algorithm to find selection