Threshold logic fixed, tests for threshold + state changes