Fix document not present error when destroying on shuitdown