implemented a signal handler for controlled shutdown