ensure proper order of destruction