Fix bugs in threshold test