Use 'close' rather than 'finish' event.
Tweak indentation.