Some refactoring.
Change close to finish and emit close after both end & finish.