Add signal handling to exit gracefully.