Shift all teardowns to deferred functions.