helper code for tuning thresholds