Fixed incorrect hysteresis functions.  Tested OK with positive upper threshold.