Fix the shutdown sequence in case of error for further analysis