rewrote event system for Typescript