Added event handling to listen for Quit events.