More robust database deletion