Increased the speed of the threshold function.