I hope this is similar to what you were lookin for!
20 events, 5 counters and 1 active. Uses 6 global values for storing of 'flags' and a Stack. I did my best to comment what was going on per event cluster but its really just a bunch of number manipulations when you break it down.
Good luck!