clean up some globals and prevent first child element from being deleted