diff --git a/autobuild.xml b/autobuild.xml
index d72846b8fea7073e607c0f4d698cb6e2481d4cce..cbaaae5c165b3e1fc22344cfb7f45a848095e9b1 100644
--- a/autobuild.xml
+++ b/autobuild.xml
@@ -2101,7 +2101,6 @@
                   <string>-G</string>
                   <string>"Visual Studio 10"</string>
                   <string>-DUNATTENDED:BOOL=ON</string>
-                  <string>-DUSE_PRECOMPILED_HEADERS=ON</string>
                   <string>-DINSTALL_PROPRIETARY=TRUE</string>
                   <string>-DUSE_KDU=FALSE</string>
                   <string>-DFMOD=FALSE</string>
@@ -2179,7 +2178,6 @@
                   <string>-G</string>
                   <string>"Visual Studio 10"</string>
                   <string>-DUNATTENDED:BOOL=ON</string>
-                  <string>-DUSE_PRECOMPILED_HEADERS=ON</string>
                   <string>-DINSTALL_PROPRIETARY=TRUE</string>
                   <string>-DUSE_KDU=FALSE</string>
                   <string>-DFMOD=FALSE</string>
@@ -2256,7 +2254,6 @@
                   <string>-G</string>
                   <string>"Visual Studio 10"</string>
                   <string>-DUNATTENDED:BOOL=ON</string>
-                  <string>-DUSE_PRECOMPILED_HEADERS=ON</string>
                   <string>-DINSTALL_PROPRIETARY=TRUE</string>
                   <string>-DUSE_KDU=FALSE</string>
                   <string>-DFMOD=FALSE</string>
diff --git a/build.sh b/build.sh
index 3d3f0d561647d9818a0468ec3614db728ee5e60d..d46da2c66d9308a39a3a95118b32d00045d17a52 100755
--- a/build.sh
+++ b/build.sh
@@ -58,7 +58,6 @@ pre_build()
     "$AUTOBUILD" configure -c $variant -- \
      -DPACKAGE:BOOL=ON \
      -DRELEASE_CRASH_REPORTING:BOOL=ON \
-     -DUSE_PRECOMPILED_HEADERS=FALSE \
      -DVIEWER_CHANNEL:STRING="\"$viewer_channel\"" \
      -DVIEWER_LOGIN_CHANNEL:STRING="\"$viewer_login_channel\"" \
      -DGRID:STRING="\"$viewer_grid\"" \
diff --git a/indra/CMakeLists.txt b/indra/CMakeLists.txt
index 310e6cbdd42a7b16c70b5fe227d95b674e0d811a..d1042d6e8693ff4692a105d24885081e6a4a233d 100644
--- a/indra/CMakeLists.txt
+++ b/indra/CMakeLists.txt
@@ -35,8 +35,10 @@ endif (NOT CMAKE_BUILD_TYPE)
 
 # For the library installation process;
 # see cmake/Prebuild.cmake for the counterpart code.
-file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/temp)
-file(WRITE ${CMAKE_BINARY_DIR}/temp/sentinel_installed "0")
+if ("${CMAKE_SOURCE_DIR}/../autobuild.xml" IS_NEWER_THAN "${CMAKE_BINARY_DIR}/temp/sentinel_installed")
+  file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/temp)
+  file(WRITE ${CMAKE_BINARY_DIR}/temp/sentinel_installed "0")
+endif ("${CMAKE_SOURCE_DIR}/../autobuild.xml" IS_NEWER_THAN "${CMAKE_BINARY_DIR}/temp/sentinel_installed")
 add_subdirectory(cmake)
 
 add_subdirectory(${LIBS_OPEN_PREFIX}llaudio)
diff --git a/indra/cmake/00-Common.cmake b/indra/cmake/00-Common.cmake
index 15b827b217d9f96abac1085d4a640aaf819fa8d8..faffdc8ccdb524e6401b786b95205e1645a2774c 100644
--- a/indra/cmake/00-Common.cmake
+++ b/indra/cmake/00-Common.cmake
@@ -36,6 +36,13 @@ if (WINDOWS)
   # Don't build DLLs.
   set(BUILD_SHARED_LIBS OFF)
 
+  # for "backwards compatibility", cmake sneaks in the Zm1000 option which royally
+  # screws incredibuild. this hack disables it.
+  # for details see: http://connect.microsoft.com/VisualStudio/feedback/details/368107/clxx-fatal-error-c1027-inconsistent-values-for-ym-between-creation-and-use-of-precompiled-headers
+  # http://www.ogre3d.org/forums/viewtopic.php?f=2&t=60015
+  # http://www.cmake.org/pipermail/cmake/2009-September/032143.html
+  string(REPLACE "/Zm1000" " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
+
   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /Zi /MDd /MP -D_SCL_SECURE_NO_WARNINGS=1"
       CACHE STRING "C++ compiler debug options" FORCE)
   set(CMAKE_CXX_FLAGS_RELWITHDEBINFO 
diff --git a/indra/cmake/LLAddBuildTest.cmake b/indra/cmake/LLAddBuildTest.cmake
index 3f259f6382e078b92dff9fe223058e501df6f51a..08feab6e36998c559cadb4ce01006787759c4537 100644
--- a/indra/cmake/LLAddBuildTest.cmake
+++ b/indra/cmake/LLAddBuildTest.cmake
@@ -95,7 +95,7 @@ INCLUDE(GoogleMock)
     IF(${name}_test_additional_INCLUDE_DIRS MATCHES NOTFOUND)
       SET(${name}_test_additional_INCLUDE_DIRS "")
     ENDIF(${name}_test_additional_INCLUDE_DIRS MATCHES NOTFOUND)
-    INCLUDE_DIRECTORIES(${alltest_INCLUDE_DIRS} ${name}_test_additional_INCLUDE_DIRS )
+    INCLUDE_DIRECTORIES(${alltest_INCLUDE_DIRS} ${${name}_test_additional_INCLUDE_DIRS} )
     IF(LL_TEST_VERBOSE)
       MESSAGE("LL_ADD_PROJECT_UNIT_TESTS ${name}_test_additional_INCLUDE_DIRS ${${name}_test_additional_INCLUDE_DIRS}")
     ENDIF(LL_TEST_VERBOSE)
diff --git a/indra/cmake/Prebuilt.cmake b/indra/cmake/Prebuilt.cmake
index 1b60d176f11d141269c664a50b71a189a2e1448a..dbb4dfc46c7f034c792224ac52a33269be1e8028 100644
--- a/indra/cmake/Prebuilt.cmake
+++ b/indra/cmake/Prebuilt.cmake
@@ -1,35 +1,49 @@
 # -*- cmake -*-
 
 include(FindAutobuild)
+if(INSTALL_PROPRIETARY)
+  include(FindSCP)
+endif(INSTALL_PROPRIETARY)
 
+# The use_prebuilt_binary macro handles automated installation of package
+# dependencies using autobuild.  The goal is that 'autobuild install' should
+# only be run when we know we need to install a new package.  This should be
+# the case in a clean checkout, or if autobuild.xml has been updated since the
+# last run (encapsulated by the file ${CMAKE_BINARY_DIR}/temp/sentinel_installed),
+# or if a previous attempt to install the package has failed (the exit status
+# of previous attempts is serialized in the file
+# ${CMAKE_BINARY_DIR}/temp/${_binary}_installed)
 macro (use_prebuilt_binary _binary)
   if (NOT DEFINED STANDALONE_${_binary})
     set(STANDALONE_${_binary} ${STANDALONE})
   endif (NOT DEFINED STANDALONE_${_binary})
 
   if (NOT STANDALONE_${_binary})
-    if(${CMAKE_BINARY_DIR}/temp/sentinel_installed IS_NEWER_THAN ${CMAKE_BINARY_DIR}/temp/${_binary}_installed)
-      if(INSTALL_PROPRIETARY)
-        include(FindSCP)
-      endif(INSTALL_PROPRIETARY)
-	  if(DEBUG_PREBUILT)
-		message("cd ${CMAKE_SOURCE_DIR} && ${AUTOBUILD_EXECUTABLE} install
-		--install-dir=${AUTOBUILD_INSTALL_DIR}
-		--skip-license-check
-		${_binary} ")
-	  endif(DEBUG_PREBUILT)
-	  execute_process(COMMAND "${AUTOBUILD_EXECUTABLE}"
-		install
-		--install-dir=${AUTOBUILD_INSTALL_DIR}
-		--skip-license-check
-		${_binary}
-		WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
-		RESULT_VARIABLE ${_binary}_installed
-		)
+    if("${${_binary}_installed}" STREQUAL "" AND EXISTS "${CMAKE_BINARY_DIR}/temp/${_binary}_installed")
+      file(READ ${CMAKE_BINARY_DIR}/temp/${_binary}_installed "${_binary}_installed")
+      if(DEBUG_PREBUILT)
+        message(STATUS "${_binary}_installed: \"${${_binary}_installed}\"")
+      endif(DEBUG_PREBUILT)
+    endif("${${_binary}_installed}" STREQUAL "" AND EXISTS "${CMAKE_BINARY_DIR}/temp/${_binary}_installed")
+
+    if(${CMAKE_BINARY_DIR}/temp/sentinel_installed IS_NEWER_THAN ${CMAKE_BINARY_DIR}/temp/${_binary}_installed OR NOT ${${_binary}_installed} EQUAL 0)
+      if(DEBUG_PREBUILT)
+        message("cd ${CMAKE_SOURCE_DIR} && ${AUTOBUILD_EXECUTABLE} install
+        --install-dir=${AUTOBUILD_INSTALL_DIR}
+        --skip-license-check
+        ${_binary} ")
+      endif(DEBUG_PREBUILT)
+      execute_process(COMMAND "${AUTOBUILD_EXECUTABLE}"
+        install
+        --install-dir=${AUTOBUILD_INSTALL_DIR}
+        --skip-license-check
+        ${_binary}
+        WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+        RESULT_VARIABLE ${_binary}_installed
+        )
       file(WRITE ${CMAKE_BINARY_DIR}/temp/${_binary}_installed "${${_binary}_installed}")
-    else(${CMAKE_BINARY_DIR}/temp/sentinel_installed IS_NEWER_THAN ${CMAKE_BINARY_DIR}/temp/${_binary}_installed)
-      set(${_binary}_installed 0)
-    endif(${CMAKE_BINARY_DIR}/temp/sentinel_installed IS_NEWER_THAN ${CMAKE_BINARY_DIR}/temp/${_binary}_installed)
+    endif(${CMAKE_BINARY_DIR}/temp/sentinel_installed IS_NEWER_THAN ${CMAKE_BINARY_DIR}/temp/${_binary}_installed OR NOT ${${_binary}_installed} EQUAL 0)
+
     if(NOT ${_binary}_installed EQUAL 0)
       message(FATAL_ERROR
               "Failed to download or unpack prebuilt '${_binary}'."
diff --git a/indra/cmake/Variables.cmake b/indra/cmake/Variables.cmake
index 03428691cfcd815744b055a28925eecc68a1acf2..2f23e7c307c6385953460269bef39dd3b512414b 100644
--- a/indra/cmake/Variables.cmake
+++ b/indra/cmake/Variables.cmake
@@ -151,7 +151,7 @@ For more information, please see JIRA DEV-14943 - Cmake Linux cannot build both
 endif (LINUX AND SERVER AND VIEWER)
 
 
-set(USE_PRECOMPILED_HEADERS OFF CACHE BOOL "Enable use of precompiled header directives where supported.")
+set(USE_PRECOMPILED_HEADERS ON CACHE BOOL "Enable use of precompiled header directives where supported.")
 
 source_group("CMake Rules" FILES CMakeLists.txt)
 
diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp
index 39daefd1ad63ce8b29827972473dadfab53d3c5c..ed192a9975125106a8ffafb4d1f72b84d59f0917 100644
--- a/indra/llcommon/llapp.cpp
+++ b/indra/llcommon/llapp.cpp
@@ -24,6 +24,10 @@
  * $/LicenseInfo$
  */
 
+#include "linden_common.h"
+
+#include "llapp.h"
+
 #include <cstdlib>
 
 #ifdef LL_DARWIN
@@ -32,9 +36,6 @@
 #include <sys/sysctl.h>
 #endif
 
-#include "linden_common.h"
-#include "llapp.h"
-
 #include "llcommon.h"
 #include "llapr.h"
 #include "llerrorcontrol.h"
diff --git a/indra/llui/llbutton.h b/indra/llui/llbutton.h
index 16aa49b65342f77e4df25e615c10eb58e13f0c96..0cfc393e05053f56a72ecec85d6fcc14adebe779 100644
--- a/indra/llui/llbutton.h
+++ b/indra/llui/llbutton.h
@@ -27,7 +27,6 @@
 #ifndef LL_LLBUTTON_H
 #define LL_LLBUTTON_H
 
-#include "lluuid.h"
 #include "llcontrol.h"
 #include "lluictrl.h"
 #include "v4color.h"
@@ -53,6 +52,8 @@ S32 round_up(S32 grid, S32 value);
 
 
 class LLUICtrlFactory;
+class LLUIImage;
+class LLUUID;
 
 //
 // Classes
diff --git a/indra/llui/llfloaterreg.h b/indra/llui/llfloaterreg.h
index 94387fb41a5b18e2b065eaf36eddc04c9b0b4a2d..8414b92113d9646864e4715dbc37c70213ea91fa 100644
--- a/indra/llui/llfloaterreg.h
+++ b/indra/llui/llfloaterreg.h
@@ -27,14 +27,9 @@
 #define LLFLOATERREG_H
 
 /// llcommon
-#include "llboost.h"
 #include "llrect.h"
-#include "llstl.h"
 #include "llsd.h"
 
-/// llui
-#include "lluictrl.h"
-
 #include <boost/function.hpp>
 
 //*******************************************************
@@ -43,6 +38,7 @@
 //
 
 class LLFloater;
+class LLUICtrl;
 
 typedef boost::function<LLFloater* (const LLSD& key)> LLFloaterBuildFunc;
 
diff --git a/indra/llui/llfocusmgr.cpp b/indra/llui/llfocusmgr.cpp
index 43e5f6b051d4f344c7e65f91a2fabc6bc67ab4dc..724d190307dcb841f96d6ebf7f30219d098eb9b8 100644
--- a/indra/llui/llfocusmgr.cpp
+++ b/indra/llui/llfocusmgr.cpp
@@ -113,6 +113,16 @@ boost::signals2::connection	LLFocusableElement::setTopLostCallback(const focus_s
 
 
 
+typedef std::list<LLHandle<LLView> > view_handle_list_t;
+typedef std::map<LLHandle<LLView>, LLHandle<LLView> > focus_history_map_t;
+struct LLFocusMgr::Impl
+{
+	// caching list of keyboard focus ancestors for calling onFocusReceived and onFocusLost
+	view_handle_list_t mCachedKeyboardFocusList;
+
+	focus_history_map_t mFocusHistory;
+};
+
 LLFocusMgr gFocusMgr;
 
 LLFocusMgr::LLFocusMgr()
@@ -123,10 +133,17 @@ LLFocusMgr::LLFocusMgr()
 	mDefaultKeyboardFocus( NULL ),
 	mKeystrokesOnly(FALSE),
 	mTopCtrl( NULL ),
-	mAppHasFocus(TRUE)   // Macs don't seem to notify us that we've gotten focus, so default to true
+	mAppHasFocus(TRUE),   // Macs don't seem to notify us that we've gotten focus, so default to true
+	mImpl(new LLFocusMgr::Impl)
 {
 }
 
+LLFocusMgr::~LLFocusMgr()
+{
+	mImpl->mFocusHistory.clear();
+	delete mImpl;
+	mImpl = NULL;
+}
 
 void LLFocusMgr::releaseFocusIfNeeded( LLView* view )
 {
@@ -179,7 +196,7 @@ void LLFocusMgr::setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock, BOOL
 		mKeyboardFocus = new_focus;
 
 		// list of the focus and it's ancestors
-		view_handle_list_t old_focus_list = mCachedKeyboardFocusList;
+		view_handle_list_t old_focus_list = mImpl->mCachedKeyboardFocusList;
 		view_handle_list_t new_focus_list;
 
 		// walk up the tree to root and add all views to the new_focus_list
@@ -206,7 +223,7 @@ void LLFocusMgr::setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock, BOOL
 			LLView* old_focus_view = old_focus_iter->get();
 			if (old_focus_view)
 			{
-				mCachedKeyboardFocusList.pop_front();
+				mImpl->mCachedKeyboardFocusList.pop_front();
 				old_focus_view->onFocusLost();
 			}
 		}
@@ -219,7 +236,7 @@ void LLFocusMgr::setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock, BOOL
 			LLView* new_focus_view = new_focus_riter->get();
 			if (new_focus_view)
 			{
-                mCachedKeyboardFocusList.push_front(new_focus_view->getHandle());
+                mImpl->mCachedKeyboardFocusList.push_front(new_focus_view->getHandle());
 				new_focus_view->onFocusReceived();
 			}
 		}
@@ -254,7 +271,7 @@ void LLFocusMgr::setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock, BOOL
 		if (focus_subtree)
 		{
 			LLView* focused_view = dynamic_cast<LLView*>(mKeyboardFocus);
-			mFocusHistory[focus_subtree->getHandle()] = focused_view ? focused_view->getHandle() : LLHandle<LLView>(); 
+			mImpl->mFocusHistory[focus_subtree->getHandle()] = focused_view ? focused_view->getHandle() : LLHandle<LLView>(); 
 		}
 	}
 	
@@ -456,8 +473,8 @@ LLUICtrl* LLFocusMgr::getLastFocusForGroup(LLView* subtree_root) const
 {
 	if (subtree_root)
 	{
-		focus_history_map_t::const_iterator found_it = mFocusHistory.find(subtree_root->getHandle());
-		if (found_it != mFocusHistory.end())
+		focus_history_map_t::const_iterator found_it = mImpl->mFocusHistory.find(subtree_root->getHandle());
+		if (found_it != mImpl->mFocusHistory.end())
 		{
 			// found last focus for this subtree
 			return static_cast<LLUICtrl*>(found_it->second.get());
@@ -470,6 +487,6 @@ void LLFocusMgr::clearLastFocusForGroup(LLView* subtree_root)
 {
 	if (subtree_root)
 	{
-		mFocusHistory.erase(subtree_root->getHandle());
+		mImpl->mFocusHistory.erase(subtree_root->getHandle());
 	}
 }
diff --git a/indra/llui/llfocusmgr.h b/indra/llui/llfocusmgr.h
index 22c1895075e70b8a5e1f5ee9d94841c79b507064..25ae1d2579d272126fa7690a476a87742c5b5785 100644
--- a/indra/llui/llfocusmgr.h
+++ b/indra/llui/llfocusmgr.h
@@ -74,7 +74,7 @@ class LLFocusMgr
 {
 public:
 	LLFocusMgr();
-	~LLFocusMgr() { mFocusHistory.clear(); }
+	~LLFocusMgr();
 
 	// Mouse Captor
 	void			setMouseCapture(LLMouseHandler* new_captor);	// new_captor = NULL to release the mouse.
@@ -120,6 +120,8 @@ class LLFocusMgr
 
 	bool			keyboardFocusHasAccelerators() const;
 
+	struct Impl;
+
 private:
 	LLUICtrl*			mLockedView;
 
@@ -132,10 +134,6 @@ class LLFocusMgr
 	LLFocusableElement*	mDefaultKeyboardFocus;
 	BOOL				mKeystrokesOnly;
 	
-	// caching list of keyboard focus ancestors for calling onFocusReceived and onFocusLost
-	typedef std::list<LLHandle<LLView> > view_handle_list_t;
-	view_handle_list_t mCachedKeyboardFocusList;
-
 	// Top View
 	LLUICtrl*			mTopCtrl;
 
@@ -143,8 +141,7 @@ class LLFocusMgr
 
 	BOOL				mAppHasFocus;
 
-	typedef std::map<LLHandle<LLView>, LLHandle<LLView> > focus_history_map_t;
-	focus_history_map_t mFocusHistory;
+	Impl * mImpl;
 };
 
 extern LLFocusMgr gFocusMgr;
diff --git a/indra/llui/lliconctrl.h b/indra/llui/lliconctrl.h
index 669e126266adced8157b393ee4dd28dca1c905c0..efa0925a4a9364b493d44ab096ae723f100962a1 100644
--- a/indra/llui/lliconctrl.h
+++ b/indra/llui/lliconctrl.h
@@ -30,6 +30,7 @@
 #include "lluuid.h"
 #include "v4color.h"
 #include "lluictrl.h"
+#include "lluiimage.h"
 #include "stdenums.h"
 
 class LLTextBox;
diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h
index 7b5fa218f23ca775e306f395d22edfd533a67e86..fe191e59714aad3a261878628799d50b7ff0670f 100644
--- a/indra/llui/lllineeditor.h
+++ b/indra/llui/lllineeditor.h
@@ -41,6 +41,7 @@
 
 #include "lleditmenuhandler.h"
 #include "lluictrl.h"
+#include "lluiimage.h"
 #include "lluistring.h"
 #include "llviewborder.h"
 
diff --git a/indra/llui/llloadingindicator.h b/indra/llui/llloadingindicator.h
index c0cb1cc74a9df96fc06566a07648e17c6e6cad24..4c47cc267cc96df4da59b263d4e6d51cd63f7d7c 100644
--- a/indra/llui/llloadingindicator.h
+++ b/indra/llui/llloadingindicator.h
@@ -28,6 +28,7 @@
 #define LL_LLLOADINGINDICATOR_H
 
 #include "lluictrl.h"
+#include "lluiimage.h"
 
 ///////////////////////////////////////////////////////////////////////////////
 // class LLLoadingIndicator
diff --git a/indra/llui/llmultislider.cpp b/indra/llui/llmultislider.cpp
index d4e6091ee037eb409fdacd391a61ef0a7913b4f8..f744e9db415dcb78f969f6c2e6ae62cb24b22bfd 100644
--- a/indra/llui/llmultislider.cpp
+++ b/indra/llui/llmultislider.cpp
@@ -35,6 +35,7 @@
 #include "llkeyboard.h"			// for the MASK constants
 #include "llcontrol.h"
 #include "lluictrlfactory.h"
+#include "lluiimage.h"
 
 #include <sstream>
 
diff --git a/indra/llui/llpanel.h b/indra/llui/llpanel.h
index c1a1a06f39c02ed8ef36e6d3d4e4c108d0b04944..7bbbeaf709cacfa8f93c5cff9623ebd53d3f1bac 100644
--- a/indra/llui/llpanel.h
+++ b/indra/llui/llpanel.h
@@ -32,6 +32,7 @@
 #include "llcallbackmap.h"
 #include "lluictrl.h"
 #include "llviewborder.h"
+#include "lluiimage.h"
 #include "lluistring.h"
 #include "v4color.h"
 #include <list>
diff --git a/indra/llui/llprogressbar.cpp b/indra/llui/llprogressbar.cpp
index ead22686bc405d21191d5aa342350a93d1bc75fe..84a890edfa59268076cb46a410038a9374685b44 100644
--- a/indra/llui/llprogressbar.cpp
+++ b/indra/llui/llprogressbar.cpp
@@ -38,6 +38,7 @@
 
 #include "llfocusmgr.h"
 #include "lluictrlfactory.h"
+#include "lluiimage.h"
 
 static LLDefaultChildRegistry::Register<LLProgressBar> r("progress_bar");
 
diff --git a/indra/llui/llprogressbar.h b/indra/llui/llprogressbar.h
index 3f308e749683feb09e748f9ef522d936ecc83e1a..a8ec83ea00434c169a0cd77bc955daf4a9a0e7e1 100644
--- a/indra/llui/llprogressbar.h
+++ b/indra/llui/llprogressbar.h
@@ -27,8 +27,9 @@
 #ifndef LL_LLPROGRESSBAR_H
 #define LL_LLPROGRESSBAR_H
 
-#include "lluictrl.h"
 #include "llframetimer.h"
+#include "lluictrl.h"
+#include "lluiimage.h"
 
 class LLProgressBar
 	: public LLUICtrl
diff --git a/indra/llui/llslider.h b/indra/llui/llslider.h
index 68823ed68e46b7619ec7c74250b1031734015997..700c17ea3e9c06ab34636eb732e5c3b7373de51a 100644
--- a/indra/llui/llslider.h
+++ b/indra/llui/llslider.h
@@ -29,6 +29,7 @@
 
 #include "llf32uictrl.h"
 #include "v4color.h"
+#include "lluiimage.h"
 
 class LLSlider : public LLF32UICtrl
 {
diff --git a/indra/llui/llstyle.cpp b/indra/llui/llstyle.cpp
index 28a064e6b60c4e4ea8c8653ecd028c44cdc1e3fb..bb731f4f7e222a01ac3c339f36b7b552f26d9d85 100644
--- a/indra/llui/llstyle.cpp
+++ b/indra/llui/llstyle.cpp
@@ -88,7 +88,7 @@ void LLStyle::setVisible(BOOL is_visible)
 	mVisible = is_visible;
 }
 
-LLUIImagePtr LLStyle::getImage() const
+LLPointer<LLUIImage> LLStyle::getImage() const
 {
 	return mImagep;
 }
diff --git a/indra/llui/llstyle.h b/indra/llui/llstyle.h
index 322edc343ce9ba1f94ac9cc73e23092e6e679ebc..9f1eba79d8c30ca56a1c9dac4fb984fda68eb95d 100644
--- a/indra/llui/llstyle.h
+++ b/indra/llui/llstyle.h
@@ -30,6 +30,7 @@
 #include "v4color.h"
 #include "llui.h"
 #include "llinitparam.h"
+#include "lluiimage.h"
 
 class LLFontGL;
 
@@ -72,7 +73,7 @@ class LLStyle : public LLRefCount
 	void setLinkHREF(const std::string& href);
 	BOOL isLink() const;
 
-	LLUIImagePtr getImage() const;
+	LLPointer<LLUIImage> getImage() const;
 	void setImage(const LLUUID& src);
 	void setImage(const std::string& name);
 
@@ -108,7 +109,7 @@ class LLStyle : public LLRefCount
 	const LLFontGL*		mFont;
 	std::string			mLink;
 	bool				mIsLink;
-	LLUIImagePtr		mImagep;
+	LLPointer<LLUIImage> mImagep;
 };
 
 typedef LLPointer<LLStyle> LLStyleSP;
diff --git a/indra/llui/lltransutil.cpp b/indra/llui/lltransutil.cpp
index 9d0ff9d5cb17ecccee1f37da8a3b51207707f514..58fa8a0828245a856e4f5730f317a192824acd65 100644
--- a/indra/llui/lltransutil.cpp
+++ b/indra/llui/lltransutil.cpp
@@ -26,10 +26,11 @@
 
 #include "linden_common.h"
 
+#include "lltransutil.h"
+
 #include "lltrans.h"
 #include "lluictrlfactory.h"
-
-#include "lltransutil.h"
+#include "llxmlnode.h"
 
 
 bool LLTransUtil::parseStrings(const std::string& xml_filename, const std::set<std::string>& default_args)
diff --git a/indra/llui/llui.h b/indra/llui/llui.h
index 6a43477693b0f54b488ec8e0b1c0af75f4308faa..c583d58d5a5076645fc797bf4bc556eb36879deb 100644
--- a/indra/llui/llui.h
+++ b/indra/llui/llui.h
@@ -33,15 +33,12 @@
 #include "llrect.h"
 #include "llcontrol.h"
 #include "llcoord.h"
-#include "lluiimage.h"		// *TODO: break this dependency, need to add #include "lluiimage.h" to all widgets that hold an Optional<LLUIImage*> in their paramblocks
 #include "llinitparam.h"
 #include "llregistry.h"
 #include "lluicolor.h"
 #include "lluicolortable.h"
 #include <boost/signals2.hpp>
 #include "lllazyvalue.h"
-#include "llhandle.h"		// *TODO: remove this dependency, added as a 
-							// convenience when LLHandle moved to llhandle.h
 #include "llframetimer.h"
 
 // LLUIFactory
@@ -265,8 +262,6 @@ class LLUI
 
 // Moved LLLocalClipRect to lllocalcliprect.h
 
-// Moved all LLHandle-related code to llhandle.h
-
 //RN: maybe this needs to moved elsewhere?
 class LLImageProviderInterface
 {
diff --git a/indra/llui/llview.h b/indra/llui/llview.h
index 61dc4b80305eae6d223ea8220a0b90d550efe018..8f167959b9ee370e94d68cb96ab420324c9c8dca 100644
--- a/indra/llui/llview.h
+++ b/indra/llui/llview.h
@@ -34,6 +34,7 @@
 #include "stdtypes.h"
 #include "llcoord.h"
 #include "llfontgl.h"
+#include "llhandle.h"
 #include "llmortician.h"
 #include "llmousehandler.h"
 #include "llstring.h"
diff --git a/indra/llui/llviewborder.cpp b/indra/llui/llviewborder.cpp
index 89cd34c37c1c231650e3aaec7b0edecd4c947683..32d7ea7c25ae46fbb47c356f6858be8d8424d4ee 100644
--- a/indra/llui/llviewborder.cpp
+++ b/indra/llui/llviewborder.cpp
@@ -28,6 +28,7 @@
 #include "llrender.h"
 #include "llfocusmgr.h"
 #include "lluictrlfactory.h"
+#include "lluiimage.h"
 
 static LLDefaultChildRegistry::Register<LLViewBorder> r("view_border");
 
diff --git a/indra/llui/llwindowshade.h b/indra/llui/llwindowshade.h
index 00471959296dd0429d0f500f5911e6d9b28756ff..09ffc2cd54ba26fe487480c8244d726fd0ff0974 100644
--- a/indra/llui/llwindowshade.h
+++ b/indra/llui/llwindowshade.h
@@ -29,6 +29,7 @@
 
 #include "lluictrl.h"
 #include "llnotifications.h"
+#include "lluiimage.h"
 
 class LLWindowShade : public LLUICtrl
 {
diff --git a/indra/llxuixml/lltrans.cpp b/indra/llxuixml/lltrans.cpp
index e13d73c6401e48364932f838f6799eff8cf87a44..b403b86048ad81e48d76f7a47e987ce3fa0d6d82 100644
--- a/indra/llxuixml/lltrans.cpp
+++ b/indra/llxuixml/lltrans.cpp
@@ -30,6 +30,7 @@
 
 #include "llfasttimer.h"	// for call count statistics
 #include "llxuiparser.h"
+#include "llxmlnode.h"
 
 #include <map>
 
diff --git a/indra/llxuixml/lltrans.h b/indra/llxuixml/lltrans.h
index 5b127b53cff94472f2f388448d7bcf430ee64dd8..b7091f77e8f6c7ab9eb0c6b25cfbfd972668086f 100644
--- a/indra/llxuixml/lltrans.h
+++ b/indra/llxuixml/lltrans.h
@@ -29,8 +29,10 @@
 
 #include <map>
 
+#include "llpointer.h"
 #include "llstring.h"
-#include "llxmlnode.h"
+
+class LLXMLNode;
 
 /**
  * @brief String template loaded from strings.xml
@@ -61,9 +63,9 @@ class LLTrans
 	 * @param default_args Set of strings (expected to be in the file) to use as default replacement args, e.g. "SECOND_LIFE"
 	 * @returns true if the file was parsed successfully, true if something went wrong
 	 */
-	static bool parseStrings(LLXMLNodePtr& root, const std::set<std::string>& default_args);
+	static bool parseStrings(LLPointer<LLXMLNode> & root, const std::set<std::string>& default_args);
 
-	static bool parseLanguageStrings(LLXMLNodePtr &root);
+	static bool parseLanguageStrings(LLPointer<LLXMLNode> & root);
 
 	/**
 	 * @brief Returns a translated string
diff --git a/indra/llxuixml/llxuiparser.h b/indra/llxuixml/llxuiparser.h
index 7a748d8aea770562f7312b2686fbe74de0fb10b8..0c38c4da936b2feb28e4e58172f4db6c2c0f6b34 100644
--- a/indra/llxuixml/llxuiparser.h
+++ b/indra/llxuixml/llxuiparser.h
@@ -28,7 +28,6 @@
 #define LLXUIPARSER_H
 
 #include "llinitparam.h"
-#include "llfasttimer.h"
 #include "llregistry.h"
 #include "llpointer.h"
 
@@ -95,6 +94,7 @@ class LLXUIXSDWriter : public LLXSDWriter
 };
 
 
+class LLXUIParserImpl;
 
 class LLXUIParser : public LLInitParam::Parser
 {
@@ -176,6 +176,7 @@ LOG_CLASS(LLXUIParser);
 // ordering of child elements from base file to localized diff file.  Then we can use a pair
 // of coroutines to perform matching of xml nodes during parsing.  Not sure if the overhead
 // of coroutines would offset the gain from SAX parsing
+class LLSimpleXUIParserImpl;
 
 class LLSimpleXUIParser : public LLInitParam::Parser
 {
diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 7319c0d902cd87c0b78ce867ff384e888928935a..8f5efcf941768d4f7755b5ef70a40cd031ea5599 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -25,10 +25,12 @@
  */
 
 #include "llviewerprecompiledheaders.h"
+
 #include "llagent.h" 
 
 #include "pipeline.h"
 
+#include "llagentaccess.h"
 #include "llagentcamera.h"
 #include "llagentlistener.h"
 #include "llagentwearables.h"
@@ -36,6 +38,7 @@
 #include "llanimationstates.h"
 #include "llbottomtray.h"
 #include "llcallingcard.h"
+#include "llcapabilitylistener.h"
 #include "llchannelmanager.h"
 #include "llconsole.h"
 #include "llfirstuse.h"
@@ -55,8 +58,10 @@
 #include "llpaneltopinfobar.h"
 #include "llparcel.h"
 #include "llrendersphere.h"
+#include "llsdmessage.h"
 #include "llsdutil.h"
 #include "llsky.h"
+#include "llslurl.h"
 #include "llsmoothstep.h"
 #include "llstartup.h"
 #include "llstatusbar.h"
@@ -74,6 +79,7 @@
 #include "llviewerobjectlist.h"
 #include "llviewerparcelmgr.h"
 #include "llviewerstats.h"
+#include "llviewerwindow.h"
 #include "llvoavatarself.h"
 #include "llwindow.h"
 #include "llworld.h"
@@ -172,7 +178,8 @@ LLAgent::LLAgent() :
 	mbRunning(false),
 	mbTeleportKeepsLookAt(false),
 
-	mAgentAccess(gSavedSettings),
+	mAgentAccess(new LLAgentAccess(gSavedSettings)),
+	mTeleportSourceSLURL(new LLSLURL),
 	mTeleportState( TELEPORT_NONE ),
 	mRegionp(NULL),
 
@@ -209,7 +216,7 @@ LLAgent::LLAgent() :
 	mAutoPilotFinishedCallback(NULL),
 	mAutoPilotCallbackData(NULL),
 	
-	mEffectColor(LLColor4(0.f, 1.f, 1.f, 1.f)),
+	mEffectColor(new LLUIColor(LLColor4(0.f, 1.f, 1.f, 1.f))),
 
 	mHaveHomePosition(FALSE),
 	mHomeRegionHandle( 0 ),
@@ -251,7 +258,7 @@ void LLAgent::init()
 
 	setFlying( gSavedSettings.getBOOL("FlyingAtExit") );
 
-	mEffectColor = LLUIColorTable::instance().getColor("EffectColor");
+	*mEffectColor = LLUIColorTable::instance().getColor("EffectColor");
 
 	gSavedSettings.getControl("PreferredMaturity")->getValidateSignal()->connect(boost::bind(&LLAgent::validateMaturity, this, _2));
 	gSavedSettings.getControl("PreferredMaturity")->getSignal()->connect(boost::bind(&LLAgent::handleMaturity, this, _2));
@@ -275,9 +282,16 @@ LLAgent::~LLAgent()
 	cleanup();
 
 	delete mMouselookModeInSignal;
+	mMouselookModeInSignal = NULL;
 	delete mMouselookModeOutSignal;
+	mMouselookModeOutSignal = NULL;
 
-	// *Note: this is where LLViewerCamera::getInstance() used to be deleted.
+	delete mAgentAccess;
+	mAgentAccess = NULL;
+	delete mEffectColor;
+	mEffectColor = NULL;
+	delete mTeleportSourceSLURL;
+	mTeleportSourceSLURL = NULL;
 }
 
 // Handle any actions that need to be performed when the main app gains focus
@@ -2142,32 +2156,32 @@ void LLAgent::onAnimStop(const LLUUID& id)
 
 bool LLAgent::isGodlike() const
 {
-	return mAgentAccess.isGodlike();
+	return mAgentAccess->isGodlike();
 }
 
 bool LLAgent::isGodlikeWithoutAdminMenuFakery() const
 {
-	return mAgentAccess.isGodlikeWithoutAdminMenuFakery();
+	return mAgentAccess->isGodlikeWithoutAdminMenuFakery();
 }
 
 U8 LLAgent::getGodLevel() const
 {
-	return mAgentAccess.getGodLevel();
+	return mAgentAccess->getGodLevel();
 }
 
 bool LLAgent::wantsPGOnly() const
 {
-	return mAgentAccess.wantsPGOnly();
+	return mAgentAccess->wantsPGOnly();
 }
 
 bool LLAgent::canAccessMature() const
 {
-	return mAgentAccess.canAccessMature();
+	return mAgentAccess->canAccessMature();
 }
 
 bool LLAgent::canAccessAdult() const
 {
-	return mAgentAccess.canAccessAdult();
+	return mAgentAccess->canAccessAdult();
 }
 
 bool LLAgent::canAccessMaturityInRegion( U64 region_handle ) const
@@ -2202,37 +2216,37 @@ bool LLAgent::canAccessMaturityAtGlobal( LLVector3d pos_global ) const
 
 bool LLAgent::prefersPG() const
 {
-	return mAgentAccess.prefersPG();
+	return mAgentAccess->prefersPG();
 }
 
 bool LLAgent::prefersMature() const
 {
-	return mAgentAccess.prefersMature();
+	return mAgentAccess->prefersMature();
 }
 	
 bool LLAgent::prefersAdult() const
 {
-	return mAgentAccess.prefersAdult();
+	return mAgentAccess->prefersAdult();
 }
 
 bool LLAgent::isTeen() const
 {
-	return mAgentAccess.isTeen();
+	return mAgentAccess->isTeen();
 }
 
 bool LLAgent::isMature() const
 {
-	return mAgentAccess.isMature();
+	return mAgentAccess->isMature();
 }
 
 bool LLAgent::isAdult() const
 {
-	return mAgentAccess.isAdult();
+	return mAgentAccess->isAdult();
 }
 
 void LLAgent::setTeen(bool teen)
 {
-	mAgentAccess.setTeen(teen);
+	mAgentAccess->setTeen(teen);
 }
 
 //static 
@@ -2277,37 +2291,37 @@ bool LLAgent::sendMaturityPreferenceToServer(int preferredMaturity)
 
 BOOL LLAgent::getAdminOverride() const	
 { 
-	return mAgentAccess.getAdminOverride(); 
+	return mAgentAccess->getAdminOverride(); 
 }
 
 void LLAgent::setMaturity(char text)
 {
-	mAgentAccess.setMaturity(text);
+	mAgentAccess->setMaturity(text);
 }
 
 void LLAgent::setAdminOverride(BOOL b)	
 { 
-	mAgentAccess.setAdminOverride(b);
+	mAgentAccess->setAdminOverride(b);
 }
 
 void LLAgent::setGodLevel(U8 god_level)	
 { 
-	mAgentAccess.setGodLevel(god_level);
+	mAgentAccess->setGodLevel(god_level);
 }
 
 void LLAgent::setAOTransition()
 {
-	mAgentAccess.setTransition();
+	mAgentAccess->setTransition();
 }
 
 const LLAgentAccess& LLAgent::getAgentAccess()
 {
-	return mAgentAccess;
+	return *mAgentAccess;
 }
 
 bool LLAgent::validateMaturity(const LLSD& newvalue)
 {
-	return mAgentAccess.canSetMaturity(newvalue.asInteger());
+	return mAgentAccess->canSetMaturity(newvalue.asInteger());
 }
 
 void LLAgent::handleMaturity(const LLSD& newvalue)
@@ -2639,12 +2653,12 @@ BOOL LLAgent::allowOperation(PermissionBit op,
 
 const LLColor4 &LLAgent::getEffectColor()
 {
-	return mEffectColor;
+	return *mEffectColor;
 }
 
 void LLAgent::setEffectColor(const LLColor4 &color)
 {
-	mEffectColor = color;
+	*mEffectColor = color;
 }
 
 void LLAgent::initOriginGlobal(const LLVector3d &origin_global)
@@ -3472,7 +3486,7 @@ void LLAgent::setTeleportState(ETeleportState state)
 
 		case TELEPORT_MOVING:
 		// We're outa here. Save "back" slurl.
-		LLAgentUI::buildSLURL(mTeleportSourceSLURL);
+		LLAgentUI::buildSLURL(*mTeleportSourceSLURL);
 			break;
 
 		case TELEPORT_ARRIVING:
@@ -3805,6 +3819,11 @@ void LLAgent::parseTeleportMessages(const std::string& xml_filename)
 	}//end for (all message sets in xml file)
 }
 
+const void LLAgent::getTeleportSourceSLURL(LLSLURL& slurl) const
+{
+	slurl = *mTeleportSourceSLURL;
+}
+
 void LLAgent::sendAgentUpdateUserInfo(bool im_via_email, const std::string& directory_visibility )
 {
 	gMessageSystem->newMessageFast(_PREHASH_UpdateUserInfo);
diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h
index 896408c0dd6a9cc0417ece00063cf1664dcd64a0..54c5649f97f3a35eea2f3487b35dc42f63a46d59 100644
--- a/indra/newview/llagent.h
+++ b/indra/newview/llagent.h
@@ -29,15 +29,11 @@
 
 #include "indra_constants.h"
 #include "llevent.h" 				// LLObservable base class
-#include "llagentaccess.h"
 #include "llagentconstants.h"
 #include "llagentdata.h" 			// gAgentID, gAgentSessionID
-#include "llcharacter.h" 			// LLAnimPauseRequest
+#include "llcharacter.h"
 #include "llcoordframe.h"			// for mFrameAgent
-#include "llpointer.h"
-#include "lluicolor.h"
 #include "llvoavatardefines.h"
-#include "llslurl.h"
 
 #include <boost/signals2.hpp>
 
@@ -56,6 +52,10 @@ class LLFriendObserver;
 class LLPickInfo;
 class LLViewerObject;
 class LLAgentDropGroupViewerNode;
+class LLAgentAccess;
+class LLSLURL;
+class LLPauseRequestHandle;
+class LLUIColor;
 
 //--------------------------------------------------------------------
 // Types
@@ -80,6 +80,8 @@ struct LLGroupData
 
 class LLAgentListener;
 
+class LLAgentImpl;
+
 //------------------------------------------------------------------------
 // LLAgent
 //------------------------------------------------------------------------
@@ -420,7 +422,7 @@ class LLAgent : public LLOldEvents::LLObservable
 	camera_signal_t* mMouselookModeInSignal;
 	camera_signal_t* mMouselookModeOutSignal;
 	BOOL            mCustomAnim; 		// Current animation is ANIM_AGENT_CUSTOMIZE ?
-	LLAnimPauseRequest mPauseRequest;
+	LLPointer<LLPauseRequestHandle> mPauseRequest;
 	BOOL			mViewsPushed; 		// Keep track of whether or not we have pushed views
 	
 /**                    Animation
@@ -515,13 +517,13 @@ class LLAgent : public LLOldEvents::LLObservable
 
 public:
 	static void 	parseTeleportMessages(const std::string& xml_filename);
-	const void getTeleportSourceSLURL(LLSLURL& slurl) const { slurl = mTeleportSourceSLURL; }
+	const void getTeleportSourceSLURL(LLSLURL& slurl) const;
 public:
 	// ! TODO ! Define ERROR and PROGRESS enums here instead of exposing the mappings.
 	static std::map<std::string, std::string> sTeleportErrorMessages;
 	static std::map<std::string, std::string> sTeleportProgressMessages;
 private:
-	LLSLURL	mTeleportSourceSLURL; 			// SLURL where last TP began
+	LLSLURL * mTeleportSourceSLURL; 			// SLURL where last TP began
 
 	//--------------------------------------------------------------------
 	// Teleport Actions
@@ -580,7 +582,7 @@ class LLAgent : public LLOldEvents::LLObservable
 	// ! BACKWARDS COMPATIBILITY ! This function can go away after the AO transition (see llstartup.cpp).
 	void 			setAOTransition();
 private:
-	LLAgentAccess 	mAgentAccess;
+	LLAgentAccess * mAgentAccess;
 	
 	//--------------------------------------------------------------------
 	// God
@@ -660,7 +662,7 @@ class LLAgent : public LLOldEvents::LLObservable
 	const LLColor4	&getEffectColor();
 	void			setEffectColor(const LLColor4 &color);
 private:
-	LLUIColor 		mEffectColor;
+	LLUIColor * mEffectColor;
 
 /**                    Rendering
  **                                                                            **
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 9de2941c4a5db2ffbafbfe98fb09300e941a2d6f..a1fe898005f6e8609cb61a34a387a44974d97277 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -82,7 +82,7 @@
 #include "lltextutil.h"
 #include "lllogininstance.h"
 #include "llprogressview.h"
-
+#include "llvocache.h"
 #include "llweb.h"
 #include "llsecondlifeurls.h"
 #include "llupdaterservice.h"
@@ -132,7 +132,6 @@
 #include "lltoolmgr.h"
 #include "llassetstorage.h"
 #include "llpolymesh.h"
-#include "llcachename.h"
 #include "llaudioengine.h"
 #include "llstreamingaudio.h"
 #include "llviewermenu.h"
diff --git a/indra/newview/lleventnotifier.h b/indra/newview/lleventnotifier.h
index 697a70876201dd7232485aff80414557bbdaa0b1..3fee46c2f67a39832979db6cd74116b4bddcfb19 100644
--- a/indra/newview/lleventnotifier.h
+++ b/indra/newview/lleventnotifier.h
@@ -31,6 +31,7 @@
 #include "v3dmath.h"
 
 class LLEventNotification;
+class LLMessageSystem;
 
 
 class LLEventNotifier
diff --git a/indra/newview/llfloaterland.cpp b/indra/newview/llfloaterland.cpp
index 7be4ebc6908406a5904c2c1c4392ba18fcc69874..0d0c1f594dca2c7f1fbf450f5bf8186245ce3e10 100644
--- a/indra/newview/llfloaterland.cpp
+++ b/indra/newview/llfloaterland.cpp
@@ -38,6 +38,7 @@
 #include "message.h"
 
 #include "llagent.h"
+#include "llagentaccess.h"
 #include "llbutton.h"
 #include "llcheckboxctrl.h"
 #include "llcombobox.h"
diff --git a/indra/newview/llfloaterland.h b/indra/newview/llfloaterland.h
index a096fb64cdb2b39ebc890f16bc9bfcb98f58edb8..8a70fa24d87d2c319e07c7751478749642f8729b 100644
--- a/indra/newview/llfloaterland.h
+++ b/indra/newview/llfloaterland.h
@@ -43,11 +43,12 @@ class LLButton;
 class LLCheckBoxCtrl;
 class LLRadioGroup;
 class LLComboBox;
-class LLNameListCtrl;
-class LLSpinCtrl;
 class LLLineEditor;
+class LLMessageSystem;
+class LLNameListCtrl;
 class LLRadioGroup;
 class LLParcelSelectionObserver;
+class LLSpinCtrl;
 class LLTabContainer;
 class LLTextBox;
 class LLTextEditor;
diff --git a/indra/newview/llfloatersnapshot.cpp b/indra/newview/llfloatersnapshot.cpp
index add591895bceb2cab6cc7443a667973c5990cbe1..00dc7b1627500a411bb3421ec5d2bbf2b500dac5 100644
--- a/indra/newview/llfloatersnapshot.cpp
+++ b/indra/newview/llfloatersnapshot.cpp
@@ -53,6 +53,7 @@
 #include "llfloaterpostcard.h"
 #include "llcheckboxctrl.h"
 #include "llradiogroup.h"
+#include "llslurl.h"
 #include "lltoolfocus.h"
 #include "lltoolmgr.h"
 #include "llwebsharing.h"
diff --git a/indra/newview/llfolderviewitem.h b/indra/newview/llfolderviewitem.h
index 2006e094a822241648c2a5be69709065f58f4b45..fc941510ab2395382a72a7d6cb1a16eb8422507f 100644
--- a/indra/newview/llfolderviewitem.h
+++ b/indra/newview/llfolderviewitem.h
@@ -28,6 +28,7 @@
 
 #include "llview.h"
 #include "lldarray.h"  // *TODO: Eliminate, forward declare
+#include "lluiimage.h"
 
 class LLFontGL;
 class LLFolderView;
diff --git a/indra/newview/lllocationhistory.h b/indra/newview/lllocationhistory.h
index 188fbf1f9badbebb43d7e733f424709c949a42d3..9fef42c5df11996246dd882ba1c4718f11533cb5 100644
--- a/indra/newview/lllocationhistory.h
+++ b/indra/newview/lllocationhistory.h
@@ -33,6 +33,7 @@
 #include <string>
 #include <map>
 #include <boost/function.hpp>
+#include <boost/signals2.hpp>
 
 class LLSD;
 /**
diff --git a/indra/newview/lloutputmonitorctrl.h b/indra/newview/lloutputmonitorctrl.h
index 026803584d8b663a457af66879d6b36f47ceea0f..2d23753d46edb1aba27085cb4f5d8c290c8fc322 100644
--- a/indra/newview/lloutputmonitorctrl.h
+++ b/indra/newview/lloutputmonitorctrl.h
@@ -31,6 +31,7 @@
 #include "llview.h"
 #include "llmutelist.h"
 #include "llspeakingindicatormanager.h"
+#include "lluiimage.h"
 
 class LLTextBox;
 class LLUICtrlFactory;
diff --git a/indra/newview/llpanelavatar.cpp b/indra/newview/llpanelavatar.cpp
index 73c4722b828f15d512a36a3fc7b1251aa1cd7be6..d58a1cb66399f1e8b7c896082b139877784451f4 100644
--- a/indra/newview/llpanelavatar.cpp
+++ b/indra/newview/llpanelavatar.cpp
@@ -36,6 +36,7 @@
 #include "llimview.h"
 #include "llmenubutton.h"
 #include "llnotificationsutil.h"
+#include "llslurl.h"
 #include "lltexteditor.h"
 #include "lltexturectrl.h"
 #include "lltoggleablemenu.h"
diff --git a/indra/newview/llpanelgroupgeneral.cpp b/indra/newview/llpanelgroupgeneral.cpp
index ec340dc258dff5964524d41dfad2889e1588f6b7..1576ccccdf3e5249bed0b605e2988e17066dc220 100644
--- a/indra/newview/llpanelgroupgeneral.cpp
+++ b/indra/newview/llpanelgroupgeneral.cpp
@@ -44,6 +44,7 @@
 #include "llnotificationsutil.h"
 #include "llscrolllistitem.h"
 #include "llspinctrl.h"
+#include "llslurl.h"
 #include "lltextbox.h"
 #include "lltexteditor.h"
 #include "lltexturectrl.h"
diff --git a/indra/newview/llpanelgrouproles.cpp b/indra/newview/llpanelgrouproles.cpp
index 3dbc637318a7eab48a77cc668a45ee554eaa7d88..fbe331c7ab925edef1c90a3faf5bd2e10cf21d76 100644
--- a/indra/newview/llpanelgrouproles.cpp
+++ b/indra/newview/llpanelgrouproles.cpp
@@ -42,6 +42,7 @@
 #include "llscrolllistctrl.h"
 #include "llscrolllistitem.h"
 #include "llscrolllistcell.h"
+#include "llslurl.h"
 #include "lltabcontainer.h"
 #include "lltextbox.h"
 #include "lltexteditor.h"
diff --git a/indra/newview/llpreviewgesture.cpp b/indra/newview/llpreviewgesture.cpp
index 8e5beb33cef116dcd53e275a9a05a8a6ea966098..9f5c55bad124c673d14131a4cc262a23b198e822 100644
--- a/indra/newview/llpreviewgesture.cpp
+++ b/indra/newview/llpreviewgesture.cpp
@@ -34,6 +34,7 @@
 #include "llassetuploadresponders.h"
 #include "llcheckboxctrl.h"
 #include "llcombobox.h"
+#include "lldatapacker.h"
 #include "lldelayedgestureerror.h"
 #include "llfloaterreg.h"
 #include "llgesturemgr.h"
diff --git a/indra/newview/llsidepaneliteminfo.cpp b/indra/newview/llsidepaneliteminfo.cpp
index c8c6858b81d2f829a4a996fa8b1f4b19a3174350..fbd2f7ca83184c47bd1fadac32b3dc3b2dc7244f 100644
--- a/indra/newview/llsidepaneliteminfo.cpp
+++ b/indra/newview/llsidepaneliteminfo.cpp
@@ -39,6 +39,7 @@
 #include "llinventoryobserver.h"
 #include "lllineeditor.h"
 #include "llradiogroup.h"
+#include "llslurl.h"
 #include "llviewercontrol.h"
 #include "llviewerinventory.h"
 #include "llviewerobjectlist.h"
diff --git a/indra/newview/lltooldraganddrop.cpp b/indra/newview/lltooldraganddrop.cpp
index ba243f258a62d0fecc536089cfe45dd335e38a8c..671a3346008e090751b1dd07b3341939a5b31a4d 100644
--- a/indra/newview/lltooldraganddrop.cpp
+++ b/indra/newview/lltooldraganddrop.cpp
@@ -35,7 +35,6 @@
 #include "llagentwearables.h"
 #include "llappearancemgr.h"
 #include "lldictionary.h"
-//#include "llfirstuse.h"
 #include "llfloaterreg.h"
 #include "llfloatertools.h"
 #include "llgesturemgr.h"
diff --git a/indra/newview/llviewerchat.cpp b/indra/newview/llviewerchat.cpp
index e7a0d17c3a42ed3e1e385437e51bd4595bfa9db8..e06fe7bda02b6466e473f2dbf651870d56fba80a 100644
--- a/indra/newview/llviewerchat.cpp
+++ b/indra/newview/llviewerchat.cpp
@@ -29,6 +29,8 @@
 
 // newview includes
 #include "llagent.h" 	// gAgent		
+#include "llslurl.h"
+#include "lluicolor.h"
 #include "lluicolortable.h"
 #include "llviewercontrol.h" // gSavedSettings
 #include "llviewerregion.h"
diff --git a/indra/newview/llviewerkeyboard.h b/indra/newview/llviewerkeyboard.h
index 925244e89bcc28295799df7f18b81ed064a1234c..ca73212ed1262f60737f545be5d333b5da02754d 100644
--- a/indra/newview/llviewerkeyboard.h
+++ b/indra/newview/llviewerkeyboard.h
@@ -28,6 +28,7 @@
 #define LL_LLVIEWERKEYBOARD_H
 
 #include "llkeyboard.h" // For EKeystate
+#include "llinitparam.h"
 
 const S32 MAX_NAMED_FUNCTIONS = 100;
 const S32 MAX_KEY_BINDINGS = 128; // was 60
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index d958551a0a8b7dceb379922ac96c413558ca5f7e..b4ec3c135b73dad5f09ee62b8c32a43ee9bafbf0 100644
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -37,6 +37,7 @@
 
 // newview includes
 #include "llagent.h"
+#include "llagentaccess.h"
 #include "llagentcamera.h"
 #include "llagentwearables.h"
 #include "llagentpilot.h"
diff --git a/indra/newview/llviewerparcelmgr.cpp b/indra/newview/llviewerparcelmgr.cpp
index c84a14f62c71833090d243fdcccd410004e0a0cf..5ae4e872f3dad6aa4287da779e0bf1906369881b 100644
--- a/indra/newview/llviewerparcelmgr.cpp
+++ b/indra/newview/llviewerparcelmgr.cpp
@@ -42,6 +42,7 @@
 
 // Viewer includes
 #include "llagent.h"
+#include "llagentaccess.h"
 #include "llviewerwindow.h"
 #include "llviewercontrol.h"
 //#include "llfirstuse.h"
@@ -54,6 +55,7 @@
 #include "llresmgr.h"
 #include "llsdutil.h"
 #include "llsdutil_math.h"
+#include "llslurl.h"
 #include "llstatusbar.h"
 #include "llui.h"
 #include "llviewertexture.h"
diff --git a/indra/newview/llviewerprecompiledheaders.h b/indra/newview/llviewerprecompiledheaders.h
index ab07adce5d3d26dfdd7942a604c87e759417bb18..45c9b3e91f24f88ca66927d041d1005886dc6dd1 100644
--- a/indra/newview/llviewerprecompiledheaders.h
+++ b/indra/newview/llviewerprecompiledheaders.h
@@ -99,8 +99,6 @@
 #include "llcoord.h"
 #include "llcoordframe.h"
 #include "llcrc.h"
-#include "llinterp.h"
-#include "llperlin.h"
 #include "llplane.h"
 #include "llquantize.h"
 #include "llrand.h"
@@ -109,7 +107,6 @@
 #include "m3math.h"
 #include "m4math.h"
 #include "llquaternion.h"
-#include "raytrace.h"
 #include "v2math.h"
 #include "v3color.h"
 #include "v3dmath.h"
@@ -117,16 +114,12 @@
 #include "v4color.h"
 #include "v4coloru.h"
 #include "v4math.h"
-////#include "vmath.h"
 #include "xform.h"
 
 // Library includes from llvfs
 #include "lldir.h"
-
-// Library includes from llmessage project
+
+// Library includes from llmessage project
 #include "llcachename.h"
 
-// llxuixml
-#include "llinitparam.h"
-
 #endif
diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp
index c53fdc339338568347a32f0ce3c9e46f7710b05b..8909abf36ef42c7e1aeb9af7cf14584302306cb5 100644
--- a/indra/newview/llviewerregion.cpp
+++ b/indra/newview/llviewerregion.cpp
@@ -46,6 +46,7 @@
 #include "llagentcamera.h"
 #include "llcallingcard.h"
 #include "llcaphttpsender.h"
+#include "llcapabilitylistener.h"
 #include "llcommandhandler.h"
 #include "lldir.h"
 #include "lleventpoll.h"
@@ -76,6 +77,71 @@
 const F32 WATER_TEXTURE_SCALE = 8.f;			//  Number of times to repeat the water texture across a region
 const S16 MAX_MAP_DIST = 10;
 
+typedef std::map<std::string, std::string> CapabilityMap;
+
+class LLViewerRegionImpl {
+public:
+	LLViewerRegionImpl(LLViewerRegion * region, LLHost const & host)
+		:	mHost(host),
+			mCompositionp(NULL),
+			mEventPoll(NULL),
+		    // I'd prefer to set the LLCapabilityListener name to match the region
+		    // name -- it's disappointing that's not available at construction time.
+		    // We could instead store an LLCapabilityListener*, making
+		    // setRegionNameAndZone() replace the instance. Would that pose
+		    // consistency problems? Can we even request a capability before calling
+		    // setRegionNameAndZone()?
+		    // For testability -- the new Michael Feathers paradigm --
+		    // LLCapabilityListener binds all the globals it expects to need at
+		    // construction time.
+		    mCapabilityListener(host.getString(), gMessageSystem, *region,
+		                        gAgent.getID(), gAgent.getSessionID())
+	{
+	}
+
+	// The surfaces and other layers
+	LLSurface*	mLandp;
+
+	// Region geometry data
+	LLVector3d	mOriginGlobal;	// Location of southwest corner of region (meters)
+	LLVector3d	mCenterGlobal;	// Location of center in world space (meters)
+	LLHost		mHost;
+
+	// The unique ID for this region.
+	LLUUID mRegionID;
+
+	// region/estate owner - usually null.
+	LLUUID mOwnerID;
+
+	// Network statistics for the region's circuit...
+	LLTimer mLastNetUpdate;
+
+	// Misc
+	LLVLComposition *mCompositionp;		// Composition layer for the surface
+
+	LLVOCacheEntry::vocache_entry_map_t		mCacheMap;
+	// time?
+	// LRU info?
+
+	// Cache ID is unique per-region, across renames, moving locations,
+	// etc.
+	LLUUID mCacheID;
+
+	CapabilityMap mCapabilities;
+	
+	LLEventPoll* mEventPoll;
+
+	/// Post an event to this LLCapabilityListener to invoke a capability message on
+	/// this LLViewerRegion's server
+	/// (https://wiki.lindenlab.com/wiki/Viewer:Messaging/Messaging_Notes#Capabilities)
+	LLCapabilityListener mCapabilityListener;
+
+	//spatial partitions for objects in this region
+	std::vector<LLSpatialPartition*> mObjectPartition;
+
+	LLHTTPClient::ResponderPtr  mHttpResponderPtr ;
+};
+
 // support for secondlife:///app/region/{REGION} SLapps
 // N.B. this is defined to work exactly like the classic secondlife://{REGION}
 // However, the later syntax cannot support spaces in the region name because
@@ -191,15 +257,12 @@ LLViewerRegion::LLViewerRegion(const U64 &handle,
 							   const U32 grids_per_region_edge, 
 							   const U32 grids_per_patch_edge, 
 							   const F32 region_width_meters)
-:	mCenterGlobal(),
+:	mImpl(new LLViewerRegionImpl(this, host)),
 	mHandle(handle),
-	mHost( host ),
 	mTimeDilation(1.0f),
 	mName(""),
 	mZoning(""),
-	mOwnerID(),
 	mIsEstateManager(FALSE),
-	mCompositionp(NULL),
 	mRegionFlags( REGION_FLAGS_DEFAULT ),
 	mSimAccess( SIM_ACCESS_MIN ),
 	mBillableFactor(1.0),
@@ -212,37 +275,27 @@ LLViewerRegion::LLViewerRegion(const U64 &handle,
 	mHttpUrl(""),
 	mCacheLoaded(FALSE),
 	mCacheDirty(FALSE),
-	mCacheID(),
-	mEventPoll(NULL),
 	mReleaseNotesRequested(FALSE),
-    // I'd prefer to set the LLCapabilityListener name to match the region
-    // name -- it's disappointing that's not available at construction time.
-    // We could instead store an LLCapabilityListener*, making
-    // setRegionNameAndZone() replace the instance. Would that pose
-    // consistency problems? Can we even request a capability before calling
-    // setRegionNameAndZone()?
-    // For testability -- the new Michael Feathers paradigm --
-    // LLCapabilityListener binds all the globals it expects to need at
-    // construction time.
-    mCapabilityListener(host.getString(), gMessageSystem, *this,
-                        gAgent.getID(), gAgent.getSessionID()),
 	mCapabilitiesReceived(false)
 {
 	mWidth = region_width_meters;
-	mOriginGlobal = from_region_handle(handle); 
+	mImpl->mOriginGlobal = from_region_handle(handle); 
 	updateRenderMatrix();
 
-	mLandp = new LLSurface('l', NULL);
+	mImpl->mLandp = new LLSurface('l', NULL);
 
 	// Create the composition layer for the surface
-	mCompositionp = new LLVLComposition(mLandp, grids_per_region_edge, region_width_meters/grids_per_region_edge);
-	mCompositionp->setSurface(mLandp);
+	mImpl->mCompositionp =
+		new LLVLComposition(mImpl->mLandp,
+							grids_per_region_edge,
+							region_width_meters / grids_per_region_edge);
+	mImpl->mCompositionp->setSurface(mImpl->mLandp);
 
 	// Create the surfaces
-	mLandp->setRegion(this);
-	mLandp->create(grids_per_region_edge,
+	mImpl->mLandp->setRegion(this);
+	mImpl->mLandp->create(grids_per_region_edge,
 					grids_per_patch_edge,
-					mOriginGlobal,
+					mImpl->mOriginGlobal,
 					mWidth);
 
 	mParcelOverlay = new LLViewerParcelOverlay(this, region_width_meters);
@@ -255,24 +308,24 @@ LLViewerRegion::LLViewerRegion(const U64 &handle,
 
 	//create object partitions
 	//MUST MATCH declaration of eObjectPartitions
-	mObjectPartition.push_back(new LLHUDPartition());		//PARTITION_HUD
-	mObjectPartition.push_back(new LLTerrainPartition());	//PARTITION_TERRAIN
-	mObjectPartition.push_back(new LLVoidWaterPartition());	//PARTITION_VOIDWATER
-	mObjectPartition.push_back(new LLWaterPartition());		//PARTITION_WATER
-	mObjectPartition.push_back(new LLTreePartition());		//PARTITION_TREE
-	mObjectPartition.push_back(new LLParticlePartition());	//PARTITION_PARTICLE
-	mObjectPartition.push_back(new LLCloudPartition());		//PARTITION_CLOUD
-	mObjectPartition.push_back(new LLGrassPartition());		//PARTITION_GRASS
-	mObjectPartition.push_back(new LLVolumePartition());	//PARTITION_VOLUME
-	mObjectPartition.push_back(new LLBridgePartition());	//PARTITION_BRIDGE
-	mObjectPartition.push_back(new LLHUDParticlePartition());//PARTITION_HUD_PARTICLE
-	mObjectPartition.push_back(NULL);						//PARTITION_NONE
+	mImpl->mObjectPartition.push_back(new LLHUDPartition());		//PARTITION_HUD
+	mImpl->mObjectPartition.push_back(new LLTerrainPartition());	//PARTITION_TERRAIN
+	mImpl->mObjectPartition.push_back(new LLVoidWaterPartition());	//PARTITION_VOIDWATER
+	mImpl->mObjectPartition.push_back(new LLWaterPartition());		//PARTITION_WATER
+	mImpl->mObjectPartition.push_back(new LLTreePartition());		//PARTITION_TREE
+	mImpl->mObjectPartition.push_back(new LLParticlePartition());	//PARTITION_PARTICLE
+	mImpl->mObjectPartition.push_back(new LLCloudPartition());		//PARTITION_CLOUD
+	mImpl->mObjectPartition.push_back(new LLGrassPartition());		//PARTITION_GRASS
+	mImpl->mObjectPartition.push_back(new LLVolumePartition());	//PARTITION_VOLUME
+	mImpl->mObjectPartition.push_back(new LLBridgePartition());	//PARTITION_BRIDGE
+	mImpl->mObjectPartition.push_back(new LLHUDParticlePartition());//PARTITION_HUD_PARTICLE
+	mImpl->mObjectPartition.push_back(NULL);						//PARTITION_NONE
 }
 
 
 void LLViewerRegion::initStats()
 {
-	mLastNetUpdate.reset();
+	mImpl->mLastNetUpdate.reset();
 	mPacketsIn = 0;
 	mBitsIn = 0;
 	mLastBitsIn = 0;
@@ -287,9 +340,9 @@ void LLViewerRegion::initStats()
 
 LLViewerRegion::~LLViewerRegion() 
 {
-	if(mHttpResponderPtr)
+	if(mImpl->mHttpResponderPtr)
 	{
-		(static_cast<BaseCapabilitiesComplete*>(mHttpResponderPtr.get()))->setRegion(NULL) ;
+		(static_cast<BaseCapabilitiesComplete*>(mImpl->mHttpResponderPtr.get()))->setRegion(NULL) ;
 	}
 
 	gVLManager.cleanupData(this);
@@ -301,21 +354,44 @@ LLViewerRegion::~LLViewerRegion()
 
 	gObjectList.killObjects(this);
 
-	delete mCompositionp;
+	delete mImpl->mCompositionp;
 	delete mParcelOverlay;
-	delete mLandp;
-	delete mEventPoll;
-	LLHTTPSender::clearSender(mHost);
+	delete mImpl->mLandp;
+	delete mImpl->mEventPoll;
+	LLHTTPSender::clearSender(mImpl->mHost);
 	
 	saveObjectCache();
 
-	std::for_each(mObjectPartition.begin(), mObjectPartition.end(), DeletePointer());
+	std::for_each(mImpl->mObjectPartition.begin(), mImpl->mObjectPartition.end(), DeletePointer());
+
+	delete mImpl;
+	mImpl = NULL;
+}
+
+LLEventPump& LLViewerRegion::getCapAPI() const
+{
+	return mImpl->mCapabilityListener.getCapAPI();
 }
 
 /*virtual*/ 
 const LLHost&	LLViewerRegion::getHost() const				
 { 
-	return mHost; 
+	return mImpl->mHost; 
+}
+
+LLSurface & LLViewerRegion::getLand() const
+{
+	return *mImpl->mLandp;
+}
+
+const LLUUID& LLViewerRegion::getRegionID() const
+{
+	return mImpl->mRegionID;
+}
+
+void LLViewerRegion::setRegionID(const LLUUID& region_id)
+{
+	mImpl->mRegionID = region_id;
 }
 
 void LLViewerRegion::loadObjectCache()
@@ -330,7 +406,7 @@ void LLViewerRegion::loadObjectCache()
 
 	if(LLVOCache::hasInstance())
 	{
-		LLVOCache::getInstance()->readFromCache(mHandle, mCacheID, mCacheMap) ;
+		LLVOCache::getInstance()->readFromCache(mHandle, mImpl->mCacheID, mImpl->mCacheMap) ;
 	}
 }
 
@@ -342,32 +418,32 @@ void LLViewerRegion::saveObjectCache()
 		return;
 	}
 
-	if (mCacheMap.empty())
+	if (mImpl->mCacheMap.empty())
 	{
 		return;
 	}
 
 	if(LLVOCache::hasInstance())
 	{
-		LLVOCache::getInstance()->writeToCache(mHandle, mCacheID, mCacheMap, mCacheDirty) ;
+		LLVOCache::getInstance()->writeToCache(mHandle, mImpl->mCacheID, mImpl->mCacheMap, mCacheDirty) ;
 		mCacheDirty = FALSE;
 	}
 
-	for(LLVOCacheEntry::vocache_entry_map_t::iterator iter = mCacheMap.begin(); iter != mCacheMap.end(); ++iter)
+	for(LLVOCacheEntry::vocache_entry_map_t::iterator iter = mImpl->mCacheMap.begin(); iter != mImpl->mCacheMap.end(); ++iter)
 	{
 		delete iter->second;
 	}
-	mCacheMap.clear();
+	mImpl->mCacheMap.clear();
 }
 
 void LLViewerRegion::sendMessage()
 {
-	gMessageSystem->sendMessage(mHost);
+	gMessageSystem->sendMessage(mImpl->mHost);
 }
 
 void LLViewerRegion::sendReliableMessage()
 {
-	gMessageSystem->sendReliable(mHost);
+	gMessageSystem->sendReliable(mImpl->mHost);
 }
 
 void LLViewerRegion::setFlags(BOOL b, U32 flags)
@@ -384,12 +460,12 @@ void LLViewerRegion::setFlags(BOOL b, U32 flags)
 
 void LLViewerRegion::setWaterHeight(F32 water_level)
 {
-	mLandp->setWaterHeight(water_level);
+	mImpl->mLandp->setWaterHeight(water_level);
 }
 
 F32 LLViewerRegion::getWaterHeight() const
 {
-	return mLandp->getWaterHeight();
+	return mImpl->mLandp->getWaterHeight();
 }
 
 BOOL LLViewerRegion::isVoiceEnabled() const
@@ -405,9 +481,9 @@ void LLViewerRegion::setRegionFlags(U32 flags)
 
 void LLViewerRegion::setOriginGlobal(const LLVector3d &origin_global) 
 { 
-	mOriginGlobal = origin_global; 
+	mImpl->mOriginGlobal = origin_global; 
 	updateRenderMatrix();
-	mLandp->setOriginGlobal(origin_global);
+	mImpl->mLandp->setOriginGlobal(origin_global);
 	mWind.setOriginGlobal(origin_global);
 	mCloudLayer.setOriginGlobal(origin_global);
 	calculateCenterGlobal();
@@ -423,16 +499,34 @@ void LLViewerRegion::setTimeDilation(F32 time_dilation)
 	mTimeDilation = time_dilation;
 }
 
+const LLVector3d & LLViewerRegion::getOriginGlobal() const
+{
+	return mImpl->mOriginGlobal;
+}
 
 LLVector3 LLViewerRegion::getOriginAgent() const
 {
-	return gAgent.getPosAgentFromGlobal(mOriginGlobal);
+	return gAgent.getPosAgentFromGlobal(mImpl->mOriginGlobal);
 }
 
+const LLVector3d & LLViewerRegion::getCenterGlobal() const
+{
+	return mImpl->mCenterGlobal;
+}
 
 LLVector3 LLViewerRegion::getCenterAgent() const
 {
-	return gAgent.getPosAgentFromGlobal(mCenterGlobal);
+	return gAgent.getPosAgentFromGlobal(mImpl->mCenterGlobal);
+}
+
+void LLViewerRegion::setOwner(const LLUUID& owner_id)
+{
+	mImpl->mOwnerID = owner_id;
+}
+
+const LLUUID& LLViewerRegion::getOwner() const
+{
+	return mImpl->mOwnerID;
 }
 
 void LLViewerRegion::setRegionNameAndZone	(const std::string& name_zone)
@@ -557,7 +651,10 @@ void LLViewerRegion::processRegionInfo(LLMessageSystem* msg, void**)
 	LLFloaterReporter::processRegionInfo(msg);
 }
 
-
+void LLViewerRegion::setCacheID(const LLUUID& id)
+{
+	mImpl->mCacheID = id;
+}
 
 S32 LLViewerRegion::renderPropertyLines()
 {
@@ -585,7 +682,7 @@ BOOL LLViewerRegion::idleUpdate(F32 max_update_time)
 {
 	LLMemType mt_ivr(LLMemType::MTYPE_IDLE_UPDATE_VIEWER_REGION);
 	// did_update returns TRUE if we did at least one significant update
-	BOOL did_update = mLandp->idleUpdate(max_update_time);
+	BOOL did_update = mImpl->mLandp->idleUpdate(max_update_time);
 	
 	if (mParcelOverlay)
 	{
@@ -600,7 +697,7 @@ BOOL LLViewerRegion::idleUpdate(F32 max_update_time)
 // As above, but forcibly do the update.
 void LLViewerRegion::forceUpdate()
 {
-	mLandp->idleUpdate(0.f);
+	mImpl->mLandp->idleUpdate(0.f);
 
 	if (mParcelOverlay)
 	{
@@ -610,17 +707,21 @@ void LLViewerRegion::forceUpdate()
 
 void LLViewerRegion::connectNeighbor(LLViewerRegion *neighborp, U32 direction)
 {
-	mLandp->connectNeighbor(neighborp->mLandp, direction);
+	mImpl->mLandp->connectNeighbor(neighborp->mImpl->mLandp, direction);
 	mCloudLayer.connectNeighbor(&(neighborp->mCloudLayer), direction);
 }
 
 
 void LLViewerRegion::disconnectAllNeighbors()
 {
-	mLandp->disconnectAllNeighbors();
+	mImpl->mLandp->disconnectAllNeighbors();
 	mCloudLayer.disconnectAllNeighbors();
 }
 
+LLVLComposition * LLViewerRegion::getComposition() const
+{
+	return mImpl->mCompositionp;
+}
 
 F32 LLViewerRegion::getCompositionXY(const S32 x, const S32 y) const
 {
@@ -714,10 +815,10 @@ F32 LLViewerRegion::getCompositionXY(const S32 x, const S32 y) const
 
 void LLViewerRegion::calculateCenterGlobal() 
 {
-	mCenterGlobal = mOriginGlobal;
-	mCenterGlobal.mdV[VX] += 0.5 * mWidth;
-	mCenterGlobal.mdV[VY] += 0.5 * mWidth;
-	mCenterGlobal.mdV[VZ] = 0.5*mLandp->getMinZ() + mLandp->getMaxZ();
+	mImpl->mCenterGlobal = mImpl->mOriginGlobal;
+	mImpl->mCenterGlobal.mdV[VX] += 0.5 * mWidth;
+	mImpl->mCenterGlobal.mdV[VY] += 0.5 * mWidth;
+	mImpl->mCenterGlobal.mdV[VZ] = 0.5 * mImpl->mLandp->getMinZ() + mImpl->mLandp->getMaxZ();
 }
 
 void LLViewerRegion::calculateCameraDistance()
@@ -728,7 +829,7 @@ void LLViewerRegion::calculateCameraDistance()
 std::ostream& operator<<(std::ostream &s, const LLViewerRegion &region)
 {
 	s << "{ ";
-	s << region.mHost;
+	s << region.mImpl->mHost;
 	s << " mOriginGlobal = " << region.getOriginGlobal()<< "\n";
     std::string name(region.getName()), zone(region.getZoning());
     if (! name.empty())
@@ -748,9 +849,9 @@ std::ostream& operator<<(std::ostream &s, const LLViewerRegion &region)
 
 void LLViewerRegion::updateNetStats()
 {
-	F32 dt = mLastNetUpdate.getElapsedTimeAndResetF32();
+	F32 dt = mImpl->mLastNetUpdate.getElapsedTimeAndResetF32();
 
-	LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit(mHost);
+	LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit(mImpl->mHost);
 	if (!cdp)
 	{
 		mAlive = false;
@@ -779,10 +880,10 @@ void LLViewerRegion::updateNetStats()
 
 U32 LLViewerRegion::getPacketsLost() const
 {
-	LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit(mHost);
+	LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit(mImpl->mHost);
 	if (!cdp)
 	{
-		llinfos << "LLViewerRegion::getPacketsLost couldn't find circuit for " << mHost << llendl;
+		llinfos << "LLViewerRegion::getPacketsLost couldn't find circuit for " << mImpl->mHost << llendl;
 		return 0;
 	}
 	else
@@ -791,6 +892,16 @@ U32 LLViewerRegion::getPacketsLost() const
 	}
 }
 
+void LLViewerRegion::setHttpResponderPtrNULL()
+{
+	mImpl->mHttpResponderPtr = NULL;
+}
+
+const LLHTTPClient::ResponderPtr LLViewerRegion::getHttpResponderPtr() const
+{
+	return mImpl->mHttpResponderPtr;
+}
+
 BOOL LLViewerRegion::pointInRegionGlobal(const LLVector3d &point_global) const
 {
 	LLVector3 pos_region = getPosRegionFromGlobal(point_global);
@@ -817,7 +928,7 @@ BOOL LLViewerRegion::pointInRegionGlobal(const LLVector3d &point_global) const
 LLVector3 LLViewerRegion::getPosRegionFromGlobal(const LLVector3d &point_global) const
 {
 	LLVector3 pos_region;
-	pos_region.setVec(point_global - mOriginGlobal);
+	pos_region.setVec(point_global - mImpl->mOriginGlobal);
 	return pos_region;
 }
 
@@ -825,7 +936,7 @@ LLVector3d LLViewerRegion::getPosGlobalFromRegion(const LLVector3 &pos_region) c
 {
 	LLVector3d pos_region_d;
 	pos_region_d.setVec(pos_region);
-	return pos_region_d + mOriginGlobal;
+	return pos_region_d + mImpl->mOriginGlobal;
 }
 
 LLVector3 LLViewerRegion::getPosAgentFromRegion(const LLVector3 &pos_region) const
@@ -842,7 +953,7 @@ LLVector3 LLViewerRegion::getPosRegionFromAgent(const LLVector3 &pos_agent) cons
 
 F32 LLViewerRegion::getLandHeightRegion(const LLVector3& region_pos)
 {
-	return mLandp->resolveHeightRegion( region_pos );
+	return mImpl->mLandp->resolveHeightRegion( region_pos );
 }
 
 bool LLViewerRegion::isAlive()
@@ -994,7 +1105,7 @@ void LLViewerRegion::updateCoarseLocations(LLMessageSystem* msg)
 		// treat the target specially for the map
 		if(i == target_index)
 		{
-			LLVector3d global_pos(mOriginGlobal);
+			LLVector3d global_pos(mImpl->mOriginGlobal);
 			global_pos.mdV[VX] += (F64)(x_pos);
 			global_pos.mdV[VY] += (F64)(y_pos);
 			global_pos.mdV[VZ] += (F64)(z_pos) * 4.0;
@@ -1034,7 +1145,7 @@ LLViewerRegion::eCacheUpdateResult LLViewerRegion::cacheFullUpdate(LLViewerObjec
 	U32 local_id = objectp->getLocalID();
 	U32 crc = objectp->getCRC();
 
-	LLVOCacheEntry* entry = get_if_there(mCacheMap, local_id, (LLVOCacheEntry*)NULL);
+	LLVOCacheEntry* entry = get_if_there(mImpl->mCacheMap, local_id, (LLVOCacheEntry*)NULL);
 
 	if (entry)
 	{
@@ -1047,10 +1158,10 @@ LLViewerRegion::eCacheUpdateResult LLViewerRegion::cacheFullUpdate(LLViewerObjec
 		}
 
 		// Update the cache entry
-		mCacheMap.erase(local_id);
+		mImpl->mCacheMap.erase(local_id);
 		delete entry;
 		entry = new LLVOCacheEntry(local_id, crc, dp);
-		mCacheMap[local_id] = entry;
+		mImpl->mCacheMap[local_id] = entry;
 		return CACHE_UPDATE_CHANGED;
 	}
 
@@ -1058,15 +1169,15 @@ LLViewerRegion::eCacheUpdateResult LLViewerRegion::cacheFullUpdate(LLViewerObjec
 
 	// Create new entry and add to map
 	eCacheUpdateResult result = CACHE_UPDATE_ADDED;
-	if (mCacheMap.size() > MAX_OBJECT_CACHE_ENTRIES)
+	if (mImpl->mCacheMap.size() > MAX_OBJECT_CACHE_ENTRIES)
 	{
-		mCacheMap.erase(mCacheMap.begin());
+		mImpl->mCacheMap.erase(mImpl->mCacheMap.begin());
 		result = CACHE_UPDATE_REPLACED;
 		
 	}
 	entry = new LLVOCacheEntry(local_id, crc, dp);
 
-	mCacheMap[local_id] = entry;
+	mImpl->mCacheMap[local_id] = entry;
 	return result;
 }
 
@@ -1076,7 +1187,7 @@ LLDataPacker *LLViewerRegion::getDP(U32 local_id, U32 crc, U8 &cache_miss_type)
 {
 	llassert(mCacheLoaded);
 
-	LLVOCacheEntry* entry = get_if_there(mCacheMap, local_id, (LLVOCacheEntry*)NULL);
+	LLVOCacheEntry* entry = get_if_there(mImpl->mCacheMap, local_id, (LLVOCacheEntry*)NULL);
 
 	if (entry)
 	{
@@ -1203,7 +1314,7 @@ void LLViewerRegion::dumpCache()
 	}
 
 	LLVOCacheEntry *entry;
-	for(LLVOCacheEntry::vocache_entry_map_t::iterator iter = mCacheMap.begin(); iter != mCacheMap.end(); ++iter)
+	for(LLVOCacheEntry::vocache_entry_map_t::iterator iter = mImpl->mCacheMap.begin(); iter != mImpl->mCacheMap.end(); ++iter)
 	{
 		entry = iter->second ;
 
@@ -1217,7 +1328,7 @@ void LLViewerRegion::dumpCache()
 		change_bin[changes]++;
 	}
 
-	llinfos << "Count " << mCacheMap.size() << llendl;
+	llinfos << "Count " << mImpl->mCacheMap.size() << llendl;
 	for (i = 0; i < BINS; i++)
 	{
 		llinfos << "Hits " << i << " " << hit_bin[i] << llendl;
@@ -1360,10 +1471,10 @@ void LLViewerRegion::setSeedCapability(const std::string& url)
 		return;
     }
 	
-	delete mEventPoll;
-	mEventPoll = NULL;
+	delete mImpl->mEventPoll;
+	mImpl->mEventPoll = NULL;
 	
-	mCapabilities.clear();
+	mImpl->mCapabilities.clear();
 	setCapability("Seed", url);
 
 	LLSD capabilityNames = LLSD::emptyArray();
@@ -1430,25 +1541,25 @@ void LLViewerRegion::setSeedCapability(const std::string& url)
 
 	llinfos << "posting to seed " << url << llendl;
 
-	mHttpResponderPtr = BaseCapabilitiesComplete::build(this) ;
-	LLHTTPClient::post(url, capabilityNames, mHttpResponderPtr);
+	mImpl->mHttpResponderPtr = BaseCapabilitiesComplete::build(this) ;
+	LLHTTPClient::post(url, capabilityNames, mImpl->mHttpResponderPtr);
 }
 
 void LLViewerRegion::setCapability(const std::string& name, const std::string& url)
 {
 	if(name == "EventQueueGet")
 	{
-		delete mEventPoll;
-		mEventPoll = NULL;
-		mEventPoll = new LLEventPoll(url, getHost());
+		delete mImpl->mEventPoll;
+		mImpl->mEventPoll = NULL;
+		mImpl->mEventPoll = new LLEventPoll(url, getHost());
 	}
 	else if(name == "UntrustedSimulatorMessage")
 	{
-		LLHTTPSender::setSender(mHost, new LLCapHTTPSender(url));
+		LLHTTPSender::setSender(mImpl->mHost, new LLCapHTTPSender(url));
 	}
 	else
 	{
-		mCapabilities[name] = url;
+		mImpl->mCapabilities[name] = url;
 		if(name == "GetTexture")
 		{
 			mHttpUrl = url ;
@@ -1463,8 +1574,8 @@ bool LLViewerRegion::isSpecialCapabilityName(const std::string &name)
 
 std::string LLViewerRegion::getCapability(const std::string& name) const
 {
-	CapabilityMap::const_iterator iter = mCapabilities.find(name);
-	if(iter == mCapabilities.end())
+	CapabilityMap::const_iterator iter = mImpl->mCapabilities.find(name);
+	if(iter == mImpl->mCapabilities.end())
 	{
 		return "";
 	}
@@ -1485,7 +1596,7 @@ void LLViewerRegion::logActiveCapabilities() const
 {
 	int count = 0;
 	CapabilityMap::const_iterator iter;
-	for (iter = mCapabilities.begin(); iter != mCapabilities.end(); iter++, count++)
+	for (iter = mImpl->mCapabilities.begin(); iter != mImpl->mCapabilities.end(); ++iter, ++count)
 	{
 		if (!iter->second.empty())
 		{
@@ -1497,9 +1608,9 @@ void LLViewerRegion::logActiveCapabilities() const
 
 LLSpatialPartition* LLViewerRegion::getSpatialPartition(U32 type)
 {
-	if (type < mObjectPartition.size())
+	if (type < mImpl->mObjectPartition.size())
 	{
-		return mObjectPartition[type];
+		return mImpl->mObjectPartition[type];
 	}
 	return NULL;
 }
diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h
index dd40b876cd4c24173ab0104d8f9374946ff50981..9c5b85b77f58a745abfdf757a0770d557ae2865b 100644
--- a/indra/newview/llviewerregion.h
+++ b/indra/newview/llviewerregion.h
@@ -33,20 +33,16 @@
 
 #include "lldarray.h"
 #include "llwind.h"
-#include "llbbox.h"
 #include "llcloud.h"
 #include "llstat.h"
 #include "v3dmath.h"
-#include "llhost.h"
 #include "llstring.h"
 #include "llregionflags.h"
 #include "lluuid.h"
-#include "lldatapacker.h"
-#include "llvocache.h"
 #include "llweb.h"
 #include "llcapabilityprovider.h"
-#include "llcapabilitylistener.h"
 #include "m4math.h"					// LLMatrix4
+#include "llhttpclient.h"
 
 // Surface id's
 #define LAND  1
@@ -65,6 +61,13 @@ class LLVOCache;
 class LLVOCacheEntry;
 class LLSpatialPartition;
 class LLEventPump;
+class LLCapabilityListener;
+class LLDataPacker;
+class LLDataPackerBinaryBuffer;
+class LLHost;
+class LLBBox;
+
+class LLViewerRegionImpl;
 
 class LLViewerRegion: public LLCapabilityProvider // implements this interface
 {
@@ -159,19 +162,19 @@ class LLViewerRegion: public LLCapabilityProvider // implements this interface
 	F32  getTimeDilation() const				{ return mTimeDilation; }
 
 	// Origin height is at zero.
-	const LLVector3d &getOriginGlobal() const	{ return mOriginGlobal; }
+	const LLVector3d &getOriginGlobal() const;
 	LLVector3 getOriginAgent() const;
 
 	// Center is at the height of the water table.
-	const LLVector3d &getCenterGlobal() const	{ return mCenterGlobal; }
+	const LLVector3d &getCenterGlobal() const;
 	LLVector3 getCenterAgent() const;
 
 	void setRegionNameAndZone(const std::string& name_and_zone);
 	const std::string& getName() const				{ return mName; }
 	const std::string& getZoning() const			{ return mZoning; }
 
-	void setOwner(const LLUUID& owner_id) { mOwnerID = owner_id; }
-	const LLUUID& getOwner() const { return mOwnerID; }
+	void setOwner(const LLUUID& owner_id);
+	const LLUUID& getOwner() const;
 
 	// Is the current agent on the estate manager list for this region?
 	void setIsEstateManager(BOOL b) { mIsEstateManager = b; }
@@ -206,7 +209,7 @@ class LLViewerRegion: public LLCapabilityProvider // implements this interface
 	// can process the message.
 	static void processRegionInfo(LLMessageSystem* msg, void**);
 
-	void setCacheID(const LLUUID& id)			{ mCacheID = id; }
+	void setCacheID(const LLUUID& id);
 
 	F32	getWidth() const						{ return mWidth; }
 
@@ -222,8 +225,8 @@ class LLViewerRegion: public LLCapabilityProvider // implements this interface
 
 	U32	getPacketsLost() const;
 
-	void setHttpResponderPtrNULL() {mHttpResponderPtr = NULL ;}
-	const LLHTTPClient::ResponderPtr getHttpResponderPtr() const {return mHttpResponderPtr ;}
+	void setHttpResponderPtrNULL();
+	const LLHTTPClient::ResponderPtr getHttpResponderPtr() const;
 
 	// Get/set named capability URLs for this region.
 	void setSeedCapability(const std::string& url);
@@ -238,21 +241,19 @@ class LLViewerRegion: public LLCapabilityProvider // implements this interface
 	static bool isSpecialCapabilityName(const std::string &name);
 	void logActiveCapabilities() const;
 
-    /// Capability-request exception
-    typedef LLCapabilityListener::ArgError ArgError;
     /// Get LLEventPump on which we listen for capability requests
     /// (https://wiki.lindenlab.com/wiki/Viewer:Messaging/Messaging_Notes#Capabilities)
-    LLEventPump& getCapAPI() { return mCapabilityListener.getCapAPI(); }
+    LLEventPump& getCapAPI() const;
 
     /// implements LLCapabilityProvider
 	/*virtual*/ const LLHost& getHost() const;
 	const U64 		&getHandle() const 			{ return mHandle; }
 
-	LLSurface		&getLand() const			{ return *mLandp; }
+	LLSurface		&getLand() const;
 
 	// set and get the region id
-	const LLUUID& getRegionID() const { return mRegionID; }
-	void setRegionID(const LLUUID& region_id) { mRegionID = region_id; }
+	const LLUUID& getRegionID() const;
+	void setRegionID(const LLUUID& region_id);
 
 	BOOL pointInRegionGlobal(const LLVector3d &point_global) const;
 	LLVector3	getPosRegionFromGlobal(const LLVector3d &point_global) const;
@@ -260,7 +261,7 @@ class LLViewerRegion: public LLCapabilityProvider // implements this interface
 	LLVector3	getPosAgentFromRegion(const LLVector3 &region_pos) const;
 	LLVector3d	getPosGlobalFromRegion(const LLVector3 &offset) const;
 
-	LLVLComposition *getComposition() const		{ return mCompositionp; }
+	LLVLComposition *getComposition() const;
 	F32 getCompositionXY(const S32 x, const S32 y) const;
 
 	BOOL isOwnedSelf(const LLVector3& pos);
@@ -347,34 +348,19 @@ class LLViewerRegion: public LLCapabilityProvider // implements this interface
 	LLDynamicArray<LLUUID> mMapAvatarIDs;
 
 private:
-	// The surfaces and other layers
-	LLSurface*	mLandp;
+	LLViewerRegionImpl * mImpl;
 
-	// Region geometry data
-	LLVector3d	mOriginGlobal;	// Location of southwest corner of region (meters)
-	LLVector3d	mCenterGlobal;	// Location of center in world space (meters)
 	F32			mWidth;			// Width of region on a side (meters)
-
 	U64			mHandle;
-	LLHost		mHost;
-
-	// The unique ID for this region.
-	LLUUID mRegionID;
-
 	F32			mTimeDilation;	// time dilation of physics simulation on simulator
 
 	// simulator name
 	std::string mName;
 	std::string mZoning;
 
-	// region/estate owner - usually null.
-	LLUUID mOwnerID;
-
 	// Is this agent on the estate managers list for this region?
 	BOOL mIsEstateManager;
 
-	// Network statistics for the region's circuit...
-	LLTimer mLastNetUpdate;
 	U32		mPacketsIn;
 	U32		mBitsIn;
 	U32		mLastBitsIn;
@@ -386,9 +372,6 @@ class LLViewerRegion: public LLCapabilityProvider // implements this interface
 	U32		mPingDelay;
 	F32		mDeltaTime;				// Time since last measurement of lastPackets, Bits, etc
 
-	// Misc
-	LLVLComposition *mCompositionp;		// Composition layer for the surface
-
 	U32		mRegionFlags;			// includes damage flags
 	U8		mSimAccess;
 	F32 	mBillableFactor;
@@ -398,46 +381,24 @@ class LLViewerRegion: public LLCapabilityProvider // implements this interface
 	// Information for Homestead / CR-53
 	S32 mClassID;
 	S32 mCPURatio;
+
 	std::string mColoName;
 	std::string mProductSKU;
 	std::string mProductName;
 	std::string mHttpUrl ;
 	
-	
 	// Maps local ids to cache entries.
 	// Regions can have order 10,000 objects, so assume
 	// a structure of size 2^14 = 16,000
 	BOOL									mCacheLoaded;
 	BOOL                                    mCacheDirty;
-	LLVOCacheEntry::vocache_entry_map_t		mCacheMap;
+
 	LLDynamicArray<U32>						mCacheMissFull;
 	LLDynamicArray<U32>						mCacheMissCRC;
-	// time?
-	// LRU info?
 
-	// Cache ID is unique per-region, across renames, moving locations,
-	// etc.
-	LLUUID mCacheID;
-
-	typedef std::map<std::string, std::string> CapabilityMap;
-	CapabilityMap mCapabilities;
-	
-	LLEventPoll* mEventPoll;
-
-    /// Post an event to this LLCapabilityListener to invoke a capability message on
-    /// this LLViewerRegion's server
-    /// (https://wiki.lindenlab.com/wiki/Viewer:Messaging/Messaging_Notes#Capabilities)
-    LLCapabilityListener mCapabilityListener;
-
-private:
 	bool	mAlive;					// can become false if circuit disconnects
 	bool	mCapabilitiesReceived;
 
-	//spatial partitions for objects in this region
-	std::vector<LLSpatialPartition*> mObjectPartition;
-
-	LLHTTPClient::ResponderPtr  mHttpResponderPtr ;
-
 	BOOL mReleaseNotesRequested;
 };
 
diff --git a/indra/newview/llviewertexturelist.h b/indra/newview/llviewertexturelist.h
index 27aab0c08191209fe2431fbc0b4ea3db522f5a04..d02b6be6b5d8ec73b6d00677ad9c652f9c3a6fcc 100644
--- a/indra/newview/llviewertexturelist.h
+++ b/indra/newview/llviewertexturelist.h
@@ -217,24 +217,24 @@ class LLUIImageList : public LLImageProviderInterface, public LLSingleton<LLUIIm
 {
 public:
 	// LLImageProviderInterface
-	/*virtual*/ LLUIImagePtr getUIImageByID(const LLUUID& id, S32 priority);
-	/*virtual*/ LLUIImagePtr getUIImage(const std::string& name, S32 priority);
+	/*virtual*/ LLPointer<LLUIImage> getUIImageByID(const LLUUID& id, S32 priority);
+	/*virtual*/ LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority);
 	void cleanUp();
 
 	bool initFromFile();
 
-	LLUIImagePtr preloadUIImage(const std::string& name, const std::string& filename, BOOL use_mips, const LLRect& scale_rect);
+	LLPointer<LLUIImage> preloadUIImage(const std::string& name, const std::string& filename, BOOL use_mips, const LLRect& scale_rect);
 	
 	static void onUIImageLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata );
 private:
-	LLUIImagePtr loadUIImageByName(const std::string& name, const std::string& filename,
+	LLPointer<LLUIImage> loadUIImageByName(const std::string& name, const std::string& filename,
 		                           BOOL use_mips = FALSE, const LLRect& scale_rect = LLRect::null, 
 		                           LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_UI);
-	LLUIImagePtr loadUIImageByID(const LLUUID& id,
+	LLPointer<LLUIImage> loadUIImageByID(const LLUUID& id,
 								 BOOL use_mips = FALSE, const LLRect& scale_rect = LLRect::null, 
 								 LLViewerTexture::EBoostLevel boost_priority = LLViewerTexture::BOOST_UI);
 
-	LLUIImagePtr loadUIImage(LLViewerFetchedTexture* imagep, const std::string& name, BOOL use_mips = FALSE, const LLRect& scale_rect = LLRect::null);
+	LLPointer<LLUIImage> loadUIImage(LLViewerFetchedTexture* imagep, const std::string& name, BOOL use_mips = FALSE, const LLRect& scale_rect = LLRect::null);
 
 
 	struct LLUIImageLoadData
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index e0202968429b6f87fd0d4e54d4709ba729689667..7728958ed8090a3400c6abde6f5e768aeca93f2b 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -79,6 +79,7 @@
 #include "lltooltip.h"
 #include "llmediaentry.h"
 #include "llurldispatcher.h"
+#include "raytrace.h"
 
 // newview includes
 #include "llagent.h"
@@ -234,17 +235,12 @@ BOOL				gDisplayCameraPos = FALSE;
 BOOL				gDisplayFOV = FALSE;
 BOOL				gDisplayBadge = FALSE;
 
-S32 CHAT_BAR_HEIGHT = 28; 
-S32 OVERLAY_BAR_HEIGHT = 20;
-
-const U8 NO_FACE = 255;
+static const U8 NO_FACE = 255;
 BOOL gQuietSnapshot = FALSE;
 
 const F32 MIN_AFK_TIME = 2.f; // minimum time after setting away state before coming back
-const F32 MAX_FAST_FRAME_TIME = 0.5f;
-const F32 FAST_FRAME_INCREMENT = 0.1f;
 
-const F32 MIN_DISPLAY_SCALE = 0.75f;
+static const F32 MIN_DISPLAY_SCALE = 0.75f;
 
 std::string	LLViewerWindow::sSnapshotBaseName;
 std::string	LLViewerWindow::sSnapshotDir;
diff --git a/indra/newview/llviewerwindow.h b/indra/newview/llviewerwindow.h
index 5eeb02b080409719e36de2205151a313fc430e13..bb0023b787a3b80400b180993f287fd2c66823c2 100644
--- a/indra/newview/llviewerwindow.h
+++ b/indra/newview/llviewerwindow.h
@@ -38,13 +38,12 @@
 
 #include "v3dmath.h"
 #include "v2math.h"
+#include "llcursortypes.h"
 #include "llwindowcallbacks.h"
 #include "lltimer.h"
 #include "llstat.h"
 #include "llmousehandler.h"
-#include "llcursortypes.h"
 #include "llhandle.h"
-#include "llimage.h"
 
 #include <boost/function.hpp>
 #include <boost/signals2.hpp>
@@ -59,6 +58,7 @@ class LLTool;
 class LLVelocityBar;
 class LLPanel;
 class LLImageRaw;
+class LLImageFormatted;
 class LLHUDIcon;
 class LLWindow;
 class LLRootView;
@@ -465,12 +465,6 @@ class LLViewerWindow : public LLWindowCallbacks
 	LLPointer<LLViewerObject>	mDragHoveredObject;
 };
 
-void toggle_flying(void*);
-void toggle_first_person();
-void toggle_build(void*);
-void reset_viewer_state_on_sim(void);
-void update_saved_window_size(const std::string& control,S32 delta_width, S32 delta_height);
-
 //
 // Globals
 //
@@ -487,8 +481,6 @@ extern LLVector3        gDebugRaycastNormal;
 extern LLVector3        gDebugRaycastBinormal;
 extern S32				gDebugRaycastFaceHit;
 
-extern S32 CHAT_BAR_HEIGHT; 
-
 extern BOOL			gDisplayCameraPos;
 extern BOOL			gDisplayWindInfo;
 extern BOOL			gDisplayFOV;
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index f1934933b5422f12ded92fb1ddc253dc2c332134..79866dc5d2bdda90cef4d3b719979e0afb5ae4aa 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -38,9 +38,9 @@
 #include <ctype.h>
 
 #include "llaudioengine.h"
-#include "llcachename.h"
 #include "noise.h"
 #include "sound_ids.h"
+#include "raytrace.h"
 
 #include "llagent.h" //  Get state values from here
 #include "llagentcamera.h"
diff --git a/indra/newview/llvotree.cpp b/indra/newview/llvotree.cpp
index 37a974be284ebe0e34107552189a247ef688ae3d..46025b46bea9887daa7d2adb9b96cf176e172f96 100644
--- a/indra/newview/llvotree.cpp
+++ b/indra/newview/llvotree.cpp
@@ -50,6 +50,7 @@
 #include "pipeline.h"
 #include "llspatialpartition.h"
 #include "llnotificationsutil.h"
+#include "raytrace.h"
 
 extern LLPipeline gPipeline;
 
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index a207d3e050d3f7ff417d8af42b1f7c79f4534995..ee54a938ba75f554dc193f4e6347960b43ce1331 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -63,6 +63,8 @@
 #include "llmediadataclient.h"
 #include "llagent.h"
 #include "llviewermediafocus.h"
+#include "lldatapacker.h"
+#include "llvocache.h"
 
 const S32 MIN_QUIET_FRAMES_COALESCE = 30;
 const F32 FORCE_SIMPLE_RENDER_AREA = 512.f;
diff --git a/indra/newview/llworld.cpp b/indra/newview/llworld.cpp
index 8f500414745079de5f68f0cb4f63c98827b81f5a..fd42058c8ab8a6c3ca283d80211c1cc02696c4e2 100644
--- a/indra/newview/llworld.cpp
+++ b/indra/newview/llworld.cpp
@@ -50,6 +50,7 @@
 #include "llviewerstats.h"
 #include "llvlcomposition.h"
 #include "llvoavatar.h"
+#include "llvocache.h"
 #include "llvowater.h"
 #include "message.h"
 #include "pipeline.h"
diff --git a/indra/newview/tests/llremoteparcelrequest_test.cpp b/indra/newview/tests/llremoteparcelrequest_test.cpp
index 9a6e08ee840e3adb99a024f3b74561dae119961e..ed66066b0ad840f97dc044d79c2b9396b0dac239 100644
--- a/indra/newview/tests/llremoteparcelrequest_test.cpp
+++ b/indra/newview/tests/llremoteparcelrequest_test.cpp
@@ -35,7 +35,6 @@
 #include "llurlentry.h"
 
 namespace {
-	LLControlGroup s_saved_settings("dummy_settings");
 	const LLUUID TEST_PARCEL_ID("11111111-1111-1111-1111-111111111111");
 }
 
@@ -64,13 +63,12 @@ LLMessageSystem * gMessageSystem;
 char const* const _PREHASH_AgentID = 0;   // never dereferenced during this test
 char const* const _PREHASH_AgentData = 0; // never dereferenced during this test
 LLAgent gAgent;
-LLAgent::LLAgent() : mAgentAccess(s_saved_settings) { }
+LLAgent::LLAgent() : mAgentAccess(NULL) { }
 LLAgent::~LLAgent() { }
 void LLAgent::sendReliableMessage(void) { }
 LLUUID gAgentSessionID;
 LLUUID gAgentID;
 LLUIColor::LLUIColor(void) { }
-LLAgentAccess::LLAgentAccess(LLControlGroup & settings) : mSavedSettings(settings) { }
 LLControlGroup::LLControlGroup(std::string const & name) : LLInstanceTracker<LLControlGroup, std::string>(name) { }
 LLControlGroup::~LLControlGroup(void) { }
 void LLUrlEntryParcel::processParcelInfo(const LLUrlEntryParcel::LLParcelData& parcel_data) { }
diff --git a/indra/newview/tests/llviewerhelputil_test.cpp b/indra/newview/tests/llviewerhelputil_test.cpp
index b425b50c8bd36a2be38d959b586c880bdb867ceb..710881d81124587d8dcb5512a030732880b87c8b 100644
--- a/indra/newview/tests/llviewerhelputil_test.cpp
+++ b/indra/newview/tests/llviewerhelputil_test.cpp
@@ -73,11 +73,9 @@ static void substitute_string(std::string &input, const std::string &search, con
 }
 
 #include "../llagent.h"
-LLAgent::LLAgent() : mAgentAccess(gSavedSettings) { }
+LLAgent::LLAgent() : mAgentAccess(NULL) { }
 LLAgent::~LLAgent() { }
 bool LLAgent::isGodlike() const { return FALSE; }
-LLAgentAccess::LLAgentAccess(LLControlGroup& settings) : mSavedSettings(settings) { }
-LLUIColor::LLUIColor() {}
 
 LLAgent gAgent;