added second thresholding algorithm