Added event emitter
Added nextTick logic for event handling