Make sure cleanups happen correctly