Properly clean up after SIGTERM (kill) and Ctrl-c