removed loop for thresholding