code doing the thresholding