Fix teardown logic