Added function to handle SIGINT better

Added an “exit_gracefully” function to handle SIGINT better.