diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp
index 40ec88f1be952982889fe59d0df66c0dca355aec..3c141aa37aa16eb0bfe5a6b17f6499e2caf95dfb 100755
--- a/indra/newview/llappearancemgr.cpp
+++ b/indra/newview/llappearancemgr.cpp
@@ -2905,15 +2905,14 @@ class RequestAgentUpdateAppearanceResponder: public LLHTTPClient::Responder
 	// Error
 	/*virtual*/ void httpFailure()
 	{
-		const LLSD& content = getContent();
-		LL_WARNS("Avatar") << "appearance update request failed "
-						   << dumpResponse() << LL_ENDL;
+		LL_WARNS("Avatar") << "appearance update request failed, status "
+						   << getStatus() << " reason " << getReason() << LL_ENDL;
 
 		if (gSavedSettings.getBOOL("DebugAvatarAppearanceMessage"))
 		{
+			const LLSD& content = getContent();
 			dumpContents(gAgentAvatarp->getFullname() + "_appearance_request_error", content);
 			debugCOF(content);
-		
 		}
 		onFailure();
 	}
@@ -2947,7 +2946,8 @@ class RequestAgentUpdateAppearanceResponder: public LLHTTPClient::Responder
 
 	void debugCOF(const LLSD& content)
 	{
-		LL_DEBUGS("Avatar") << "AIS COF, version found: " << content["expected"].asInteger() << llendl;
+		LL_INFOS("Avatar") << "AIS COF, version received: " << content["expected"].asInteger()
+						   << " ================================= " << llendl;
 		std::set<LLUUID> ais_items, local_items;
 		const LLSD& cof_raw = content["cof_raw"];
 		for (LLSD::array_const_iterator it = cof_raw.beginArray();
@@ -2959,30 +2959,32 @@ class RequestAgentUpdateAppearanceResponder: public LLHTTPClient::Responder
 				ais_items.insert(item["item_id"].asUUID());
 				if (item["type"].asInteger() == 24) // link
 				{
-					LL_DEBUGS("Avatar") << "Link: item_id: " << item["item_id"].asUUID()
-										<< " linked_item_id: " << item["asset_id"].asUUID()
-										<< " name: " << item["name"].asString()
-										<< llendl; 
+					LL_INFOS("Avatar") << "AIS Link: item_id: " << item["item_id"].asUUID()
+									   << " linked_item_id: " << item["asset_id"].asUUID()
+									   << " name: " << item["name"].asString()
+									   << llendl; 
 				}
 				else if (item["type"].asInteger() == 25) // folder link
 				{
-					LL_DEBUGS("Avatar") << "Folder link: item_id: " << item["item_id"].asUUID()
-										<< " linked_item_id: " << item["asset_id"].asUUID()
-										<< " name: " << item["name"].asString()
-										<< llendl; 
+					LL_INFOS("Avatar") << "AIS Folder link: item_id: " << item["item_id"].asUUID()
+									   << " linked_item_id: " << item["asset_id"].asUUID()
+									   << " name: " << item["name"].asString()
+									   << llendl; 
 					
 				}
 				else
 				{
-					LL_DEBUGS("Avatar") << "Other: item_id: " << item["item_id"].asUUID()
-										<< " linked_item_id: " << item["asset_id"].asUUID()
-										<< " name: " << item["name"].asString()
-										<< llendl; 
+					LL_INFOS("Avatar") << "AIS Other: item_id: " << item["item_id"].asUUID()
+									   << " linked_item_id: " << item["asset_id"].asUUID()
+									   << " name: " << item["name"].asString()
+									   << " type: " << item["type"].asInteger()
+									   << llendl; 
 				}
 			}
 		}
-		LL_DEBUGS("Avatar") << llendl;
-		LL_DEBUGS("Avatar") << "Local COF, version requested: " << content["observed"].asInteger() << llendl;
+		LL_INFOS("Avatar") << llendl;
+		LL_INFOS("Avatar") << "Local COF, version requested: " << content["observed"].asInteger() 
+						   << " ================================= " << llendl;
 		LLInventoryModel::cat_array_t cat_array;
 		LLInventoryModel::item_array_t item_array;
 		gInventory.collectDescendents(LLAppearanceMgr::instance().getCOF(),
@@ -2991,26 +2993,34 @@ class RequestAgentUpdateAppearanceResponder: public LLHTTPClient::Responder
 		{
 			const LLViewerInventoryItem* inv_item = item_array.get(i).get();
 			local_items.insert(inv_item->getUUID());
-			LL_DEBUGS("Avatar") << "item_id: " << inv_item->getUUID()
-								<< " linked_item_id: " << inv_item->getLinkedUUID()
-								<< " name: " << inv_item->getName()
-								<< llendl;
+			LL_INFOS("Avatar") << "LOCAL: item_id: " << inv_item->getUUID()
+							   << " linked_item_id: " << inv_item->getLinkedUUID()
+							   << " name: " << inv_item->getName()
+							   << " parent: " << inv_item->getParentUUID()
+							   << llendl;
 		}
-		LL_DEBUGS("Avatar") << llendl;
+		LL_INFOS("Avatar") << " ================================= " << llendl;
 		for (std::set<LLUUID>::iterator it = local_items.begin(); it != local_items.end(); ++it)
 		{
 			if (ais_items.find(*it) == ais_items.end())
 			{
-				LL_DEBUGS("Avatar") << "LOCAL ONLY: " << *it << llendl;
+				LL_INFOS("Avatar") << "LOCAL ONLY: " << *it << llendl;
 			}
 		}
 		for (std::set<LLUUID>::iterator it = ais_items.begin(); it != ais_items.end(); ++it)
 		{
 			if (local_items.find(*it) == local_items.end())
 			{
-				LL_DEBUGS("Avatar") << "AIS ONLY: " << *it << llendl;
+				LL_INFOS("Avatar") << "AIS ONLY: " << *it << llendl;
 			}
 		}
+		if (local_items.size()==0 && ais_items.size()==0)
+		{
+			LL_INFOS("Avatar") << "COF contents identical, only version numbers differ (req "
+							   << content["observed"].asInteger()
+							   << " rcv " << content["expected"].asInteger()
+							   << ")" << llendl;
+		}
 	}
 
 	LLPointer<LLHTTPRetryPolicy> mRetryPolicy;
diff --git a/indra/newview/llinventorymodel.cpp b/indra/newview/llinventorymodel.cpp
index bb5da2e9dbda9ab230574962ec4c28c2808fe326..b49e617f6219bf0f4bc4cdda32e3cb340e56cf79 100755
--- a/indra/newview/llinventorymodel.cpp
+++ b/indra/newview/llinventorymodel.cpp
@@ -1197,14 +1197,39 @@ void LLInventoryModel::onDescendentsPurgedFromServer(const LLUUID& object_id)
 		}
 
 		count = categories.count();
-		for(S32 i = 0; i < count; ++i)
+		// Slightly kludgy way to make sure categories are removed
+		// only after their child categories have gone away.
+
+		// FIXME: Would probably make more sense to have this whole
+		// descendent-clearing thing be a post-order recursive
+		// function to get the leaf-up behavior automatically.
+		S32 deleted_count;
+		S32 total_deleted_count = 0;
+		do
 		{
-			uu_id = categories.get(i)->getUUID();
-			if (getCategory(uu_id))
+			deleted_count = 0;
+			for(S32 i = 0; i < count; ++i)
 			{
-				deleteObject(uu_id);
+				uu_id = categories.get(i)->getUUID();
+				if (getCategory(uu_id))
+				{
+					cat_array_t* cat_list = getUnlockedCatArray(uu_id);
+					if (!cat_list || (cat_list->size() == 0))
+					{
+						deleteObject(uu_id);
+						deleted_count++;
+					}
+				}
 			}
+			total_deleted_count += deleted_count;
+		}
+		while (deleted_count > 0);
+		if (total_deleted_count != count)
+		{
+			llwarns << "Unexpected count of categories deleted, got "
+					<< total_deleted_count << " expected " << count << llendl;
 		}
+		gInventory.validate();
 	}
 }
 
@@ -1258,12 +1283,20 @@ void LLInventoryModel::deleteObject(const LLUUID& id)
 	item_list = getUnlockedItemArray(id);
 	if(item_list)
 	{
+		if (item_list->size())
+		{
+			llwarns << "Deleting cat " << id << " while it still has child items" << llendl;
+		}
 		delete item_list;
 		mParentChildItemTree.erase(id);
 	}
 	cat_list = getUnlockedCatArray(id);
 	if(cat_list)
 	{
+		if (cat_list->size())
+		{
+			llwarns << "Deleting cat " << id << " while it still has child cats" << llendl;
+		}
 		delete cat_list;
 		mParentChildCategoryTree.erase(id);
 	}
@@ -2084,11 +2117,16 @@ void LLInventoryModel::buildParentChildMap()
 	S32 count = cats.count();
 	S32 i;
 	S32 lost = 0;
+	cat_array_t lost_cats;
 	for(i = 0; i < count; ++i)
 	{
 		LLViewerInventoryCategory* cat = cats.get(i);
 		catsp = getUnlockedCatArray(cat->getParentUUID());
-		if(catsp)
+		if(catsp &&
+		   // Only the two root folders should be children of null.
+		   // Others should go to lost & found.
+		   (cat->getParentUUID().notNull() || 
+			cat->getPreferredType() == LLFolderType::FT_ROOT_INVENTORY ))
 		{
 			catsp->put(cat);
 		}
@@ -2103,34 +2141,7 @@ void LLInventoryModel::buildParentChildMap()
 			llinfos << "Lost category: " << cat->getUUID() << " - "
 					<< cat->getName() << llendl;
 			++lost;
-			// plop it into the lost & found.
-			LLFolderType::EType pref = cat->getPreferredType();
-			if(LLFolderType::FT_NONE == pref)
-			{
-				cat->setParent(findCategoryUUIDForType(LLFolderType::FT_LOST_AND_FOUND));
-			}
-			else if(LLFolderType::FT_ROOT_INVENTORY == pref)
-			{
-				// it's the root
-				cat->setParent(LLUUID::null);
-			}
-			else
-			{
-				// it's a protected folder.
-				cat->setParent(gInventory.getRootFolderID());
-			}
-			// FIXME note that updateServer() fails with protected
-			// types, so this will not work as intended in that case.
-			cat->updateServer(TRUE);
-			catsp = getUnlockedCatArray(cat->getParentUUID());
-			if(catsp)
-			{
-				catsp->put(cat);
-			}
-			else
-			{		
-				llwarns << "Lost and found Not there!!" << llendl;
-			}
+			lost_cats.put(cat);
 		}
 	}
 	if(lost)
@@ -2138,6 +2149,42 @@ void LLInventoryModel::buildParentChildMap()
 		llwarns << "Found  " << lost << " lost categories." << llendl;
 	}
 
+	// Do moves in a separate pass to make sure we've properly filed
+	// the FT_LOST_AND_FOUND category before we try to find its UUID.
+	for(i = 0; i<lost_cats.count(); ++i)
+	{
+		LLViewerInventoryCategory *cat = lost_cats.get(i);
+
+		// plop it into the lost & found.
+		LLFolderType::EType pref = cat->getPreferredType();
+		if(LLFolderType::FT_NONE == pref)
+		{
+			cat->setParent(findCategoryUUIDForType(LLFolderType::FT_LOST_AND_FOUND));
+		}
+		else if(LLFolderType::FT_ROOT_INVENTORY == pref)
+		{
+			// it's the root
+			cat->setParent(LLUUID::null);
+		}
+		else
+		{
+			// it's a protected folder.
+			cat->setParent(gInventory.getRootFolderID());
+		}
+		// FIXME note that updateServer() fails with protected
+		// types, so this will not work as intended in that case.
+		cat->updateServer(TRUE);
+		catsp = getUnlockedCatArray(cat->getParentUUID());
+		if(catsp)
+		{
+			catsp->put(cat);
+		}
+		else
+		{		
+			llwarns << "Lost and found Not there!!" << llendl;
+		}
+	}
+
 	const BOOL COF_exists = (findCategoryUUIDForType(LLFolderType::FT_CURRENT_OUTFIT, FALSE) != LLUUID::null);
 	sFirstTimeInViewer2 = !COF_exists || gAgent.isFirstLogin();
 
@@ -2267,10 +2314,10 @@ void LLInventoryModel::buildParentChildMap()
 		}
 	}
 
-	// if (!gInventory.validate())
-	// {
-	// 	llwarns << "model failed validity check!" << llendl;
-	// }
+	if (!gInventory.validate())
+	{
+	 	llwarns << "model failed validity check!" << llendl;
+	}
 }
 
 struct LLUUIDAndName