added special shutdown hook to ensure graceful shutdown on mac if shut down using the menu bar or keyboard shortcuts (cmd-Q)