Added integer and range check for threshold variable.