guarantee correct cleanup order