Added EventEmitter; fixed numerous bugs.