rewrite using EventEmitter