workable demo: adjusted the sample time @BB, simplify the threshold calculation, etc