Revised the logic for when to call log_exit() to handle the