fix(events): refactor code to use the event emitter pattern