fix crash on auto close
add real thresholding