completed part 2: selectThreshold