Fix bug in determining threshold range