added threshold variable