simpler algorithm for threshold-finding