added thresholding function