Added better thresholding