Fix close event being emitted multiple times