Move the drain functions further down. This fixes the panic on detach.