added iterative thresholding to detection routines