Fixed some bugs, changed threshold rules.