(shutdown_handler): New function to exit cleanly on shutdown.