Improve cleaning function for root node