Refactor event emitters to make sure errors are only emitted once before the closing procedure is started.