diff --git a/indra/newview/llpanelteleporthistory.cpp b/indra/newview/llpanelteleporthistory.cpp
index 79171dbcb9297d9d74106de47a7e16ad3f7297f9..2c3f76f5462d666904beb06122b38224ccaf8a8b 100644
--- a/indra/newview/llpanelteleporthistory.cpp
+++ b/indra/newview/llpanelteleporthistory.cpp
@@ -679,29 +679,32 @@ void LLTeleportHistoryPanel::refresh()
 			// tab_boundary_date would be earliest possible date for this tab
 			S32 tab_idx = 0;
 			getNextTab(date, tab_idx, tab_boundary_date);
-
-			LLAccordionCtrlTab* tab = mItemContainers.get(mItemContainers.size() - 1 - tab_idx);
-			tab->setVisible(true);
-
-			// Expand all accordion tabs when filtering
-			if(!sFilterSubString.empty())
+			tab_idx = mItemContainers.size() - 1 - tab_idx;
+			if (tab_idx >= 0)
 			{
-				//store accordion tab state when filter is not empty
-				tab->notifyChildren(LLSD().with("action","store_state"));
-				
-				tab->setDisplayChildren(true);
-			}
-			// Restore each tab's expand state when not filtering
-			else
-			{
-				bool collapsed = isAccordionCollapsedByUser(tab);
-				tab->setDisplayChildren(!collapsed);
+				LLAccordionCtrlTab* tab = mItemContainers.get(tab_idx);
+				tab->setVisible(true);
+
+				// Expand all accordion tabs when filtering
+				if(!sFilterSubString.empty())
+				{
+					//store accordion tab state when filter is not empty
+					tab->notifyChildren(LLSD().with("action","store_state"));
 				
-				//restore accordion state after all those accodrion tabmanipulations
-				tab->notifyChildren(LLSD().with("action","restore_state"));
-			}
+					tab->setDisplayChildren(true);
+				}
+				// Restore each tab's expand state when not filtering
+				else
+				{
+					bool collapsed = isAccordionCollapsedByUser(tab);
+					tab->setDisplayChildren(!collapsed);
+			
+					//restore accordion state after all those accodrion tabmanipulations
+					tab->notifyChildren(LLSD().with("action","restore_state"));
+				}
 
-			curr_flat_view = getFlatListViewFromTab(tab);
+				curr_flat_view = getFlatListViewFromTab(tab);
+			}
 		}
 
 		if (curr_flat_view)
@@ -760,7 +763,12 @@ void LLTeleportHistoryPanel::onTeleportHistoryChange(S32 removed_index)
 void LLTeleportHistoryPanel::replaceItem(S32 removed_index)
 {
 	// Flat list for 'Today' (mItemContainers keeps accordion tabs in reverse order)
-	LLFlatListView* fv = getFlatListViewFromTab(mItemContainers[mItemContainers.size() - 1]);
+	LLFlatListView* fv = NULL;
+	
+	if (mItemContainers.size() > 0)
+	{
+		fv = getFlatListViewFromTab(mItemContainers[mItemContainers.size() - 1]);
+	}
 
 	// Empty flat list for 'Today' means that other flat lists are empty as well,
 	// so all items from teleport history should be added.
@@ -828,19 +836,27 @@ void LLTeleportHistoryPanel::showTeleportHistory()
 
 	// Starting to add items from last one, in reverse order,
 	// since TeleportHistory keeps most recent item at the end
+	if (!mTeleportHistory)
+	{
+		mTeleportHistory = LLTeleportHistoryStorage::getInstance();
+	}
+
 	mCurrentItem = mTeleportHistory->getItems().size() - 1;
 
 	for (S32 n = mItemContainers.size() - 1; n >= 0; --n)
 	{
 		LLAccordionCtrlTab* tab = mItemContainers.get(n);
-		tab->setVisible(false);
-
-		LLFlatListView* fv = getFlatListViewFromTab(tab);
-		if (fv)
+		if (tab)
 		{
-			// Detached panels are managed by LLTeleportHistoryFlatItemStorage
-			std::vector<LLPanel*> detached_items;
-			fv->detachItems(detached_items);
+			tab->setVisible(false);
+
+			LLFlatListView* fv = getFlatListViewFromTab(tab);
+			if (fv)
+			{
+				// Detached panels are managed by LLTeleportHistoryFlatItemStorage
+				std::vector<LLPanel*> detached_items;
+				fv->detachItems(detached_items);
+			}
 		}
 	}
 }
diff --git a/indra/newview/llteleporthistorystorage.cpp b/indra/newview/llteleporthistorystorage.cpp
index 0ba455e7d5b5de3b90c0844ce1eabf3f6eeff2c6..af5a047da4d974c4d77f5e0e78fcefc37977b4fa 100644
--- a/indra/newview/llteleporthistorystorage.cpp
+++ b/indra/newview/llteleporthistorystorage.cpp
@@ -66,6 +66,7 @@ struct LLSortItemsByDate
 LLTeleportHistoryStorage::LLTeleportHistoryStorage() :
 	mFilename("teleport_history.txt")
 {
+	mItems.clear();
 	LLTeleportHistory *th = LLTeleportHistory::getInstance();
 	if (th)
 		th->setHistoryChangedCallback(boost::bind(&LLTeleportHistoryStorage::onTeleportHistoryChange, this));