Located and fixed major bug. "else if (tsv < th)" changed to "else if (tsv < -th)".