Added hook for safe shutdown