Updated to allow different thresh values