Fixing bug in threshold checking