thresholding works better

significantly improved performance of thresholding.py, much still to do