add binary search of threshold