Fixed some bugs with event counting. Still not working.