Revert "Revert "fixed order of teardown""

This reverts commit 8d642b14ecb7f94564f309d93f8514ca2071f364.