Make hook shutdown more reliable