Line 3 -7 implements the segment-based decoding, and line 8 -11 implements the best-first clustering.
the first stage alone is unlikely to detect E2 and E4 as events due to the difficulties described above.