First working version with event emitter