Added thresholding based on standard deviation