diff --git a/indra/llcommon/llcommonutils.h b/indra/llcommon/llcommonutils.h
index 755dc41fb4c1dfe98c68b7a500a7009918450eb3..20ada27830835d4bb6f78dede5144c2d936dd873 100755
--- a/indra/llcommon/llcommonutils.h
+++ b/indra/llcommon/llcommonutils.h
@@ -27,6 +27,8 @@
 #ifndef LL_LLCOMMONUTILS_H
 #define LL_LLCOMMONUTILS_H
 
+#include "lluuid.h"
+
 namespace LLCommonUtils
 {
 	/**
diff --git a/indra/llcommon/llcriticaldamp.cpp b/indra/llcommon/llcriticaldamp.cpp
index 575fc4149e00d8c651cda2b6952298ff787006af..5ffad88973ec3243e6844bc401173692613e15fa 100755
--- a/indra/llcommon/llcriticaldamp.cpp
+++ b/indra/llcommon/llcriticaldamp.cpp
@@ -81,7 +81,7 @@ void LLSmoothInterpolation::updateInterpolants()
 //-----------------------------------------------------------------------------
 // getInterpolant()
 //-----------------------------------------------------------------------------
-F32 LLSmoothInterpolation::getInterpolant(LLUnit<F32, LLUnits::Seconds> time_constant, bool use_cache)
+F32 LLSmoothInterpolation::getInterpolant(LLUnitImplicit<F32, LLUnits::Seconds> time_constant, bool use_cache)
 {
 	if (time_constant == 0.f)
 	{
diff --git a/indra/llcommon/llcriticaldamp.h b/indra/llcommon/llcriticaldamp.h
index e174643cd0e8ab019e71fe875a2f71aeb0aaf420..7b2a41445976e83da1d0586d4c469d31318d6f62 100755
--- a/indra/llcommon/llcriticaldamp.h
+++ b/indra/llcommon/llcriticaldamp.h
@@ -42,10 +42,10 @@ class LL_COMMON_API LLSmoothInterpolation
 	static void updateInterpolants();
 
 	// ACCESSORS
-	static F32 getInterpolant(LLUnit<F32, LLUnits::Seconds> time_constant, bool use_cache = true);
+	static F32 getInterpolant(LLUnitImplicit<F32, LLUnits::Seconds> time_constant, bool use_cache = true);
 
 	template<typename T> 
-	static T lerp(T a, T b, LLUnit<F32, LLUnits::Seconds> time_constant, bool use_cache = true)
+	static T lerp(T a, T b, LLUnitImplicit<F32, LLUnits::Seconds> time_constant, bool use_cache = true)
 	{
 		F32 interpolant = getInterpolant(time_constant, use_cache);
 		return ((a * (1.f - interpolant)) 
diff --git a/indra/llcommon/lldate.cpp b/indra/llcommon/lldate.cpp
index 7892269e350f9a4c491fbbeeff545d967e9aef88..cec4047c1f4b9aab1bb927e8a09d3c9039e45419 100755
--- a/indra/llcommon/lldate.cpp
+++ b/indra/llcommon/lldate.cpp
@@ -55,7 +55,7 @@ LLDate::LLDate(const LLDate& date) :
 	mSecondsSinceEpoch(date.mSecondsSinceEpoch)
 {}
 
-LLDate::LLDate(LLUnit<F64, LLUnits::Seconds> seconds_since_epoch) :
+LLDate::LLDate(LLUnitImplicit<F64, LLUnits::Seconds> seconds_since_epoch) :
 	mSecondsSinceEpoch(seconds_since_epoch.value())
 {}
 
diff --git a/indra/llcommon/lldate.h b/indra/llcommon/lldate.h
index 1067ac528053de01eacbc56df8d4b694e0f58615..816bc62b141cb45853685fca3e52ce017082faad 100755
--- a/indra/llcommon/lldate.h
+++ b/indra/llcommon/lldate.h
@@ -59,7 +59,7 @@ class LL_COMMON_API LLDate
 	 *
 	 * @param seconds_since_epoch The number of seconds since UTC epoch.
 	 */
-	LLDate(LLUnit<F64, LLUnits::Seconds> seconds_since_epoch);
+	LLDate(LLUnitImplicit<F64, LLUnits::Seconds> seconds_since_epoch);
 
 	/** 
 	 * @brief Construct a date from a string representation
diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp
index 79aa0c87228571c26adb29118fc70f859b03f4b7..6f046c18ff4f785f552b15551ea39ab1a415665b 100755
--- a/indra/llcommon/llfasttimer.cpp
+++ b/indra/llcommon/llfasttimer.cpp
@@ -111,9 +111,9 @@ static timer_tree_dfs_iterator_t end_timer_tree()
 struct SortTimerByName
 {
 	bool operator()(const TimeBlock* i1, const TimeBlock* i2)
-	{
+        {
 		return i1->getName() < i2->getName();
-	}
+        }
 };
 
 TimeBlock& TimeBlock::getRootTimeBlock()
@@ -227,17 +227,17 @@ void TimeBlock::incrementalUpdateTimerTree()
 
 			if (accumulator->mMoveUpTree)
 			{
-					// since ancestors have already been visited, re-parenting won't affect tree traversal
+				// since ancestors have already been visited, re-parenting won't affect tree traversal
 				//step up tree, bringing our descendants with us
 				LL_DEBUGS("FastTimers") << "Moving " << timerp->getName() << " from child of " << timerp->getParent()->getName() <<
 					" to child of " << timerp->getParent()->getParent()->getName() << LL_ENDL;
 				timerp->setParent(timerp->getParent()->getParent());
-					accumulator->mParent = timerp->getParent();
-					accumulator->mMoveUpTree = false;
+				accumulator->mParent = timerp->getParent();
+				accumulator->mMoveUpTree = false;
 
 				// don't bubble up any ancestors until descendants are done bubbling up
-					// as ancestors may call this timer only on certain paths, so we want to resolve
-					// child-most block locations before their parents
+				// as ancestors may call this timer only on certain paths, so we want to resolve
+				// child-most block locations before their parents
 				it.skipAncestors();
 			}
 		}
@@ -357,7 +357,7 @@ void TimeBlock::logStats()
 				// doesn't work correctly on the first frame
 				total_time += frame_recording.getLastRecording().getSum(timer);
 			}
-		}
+}
 
 		sd["Total"]["Time"] = (LLSD::Real) total_time.value();
 		sd["Total"]["Calls"] = (LLSD::Integer) 1;
@@ -366,7 +366,7 @@ void TimeBlock::logStats()
 			LLMutexLock lock(sLogLock);
 			sLogQueue.push(sd);
 		}
-	}
+}
 
 }
 
@@ -413,7 +413,7 @@ void TimeBlock::writeLog(std::ostream& os)
 		LLSDSerialize::toXML(sd, os);
 		LLMutexLock lock(sLogLock);
 		sLogQueue.pop();
-	}
+			}
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -470,7 +470,7 @@ LLUnit<F64, LLUnits::Seconds> BlockTimer::getElapsedTime()
 {
 	U64 total_time = TimeBlock::getCPUClockCount64() - mStartTime;
 
-	return (F64)total_time / (F64)TimeBlock::countsPerSecond();
+	return LLUnits::Seconds::fromValue((F64)total_time / (F64)TimeBlock::countsPerSecond());
 }
 
 
diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h
index 879ea4fe2a1235c38cfb0940d61e7bfb5e7cd6a0..812071efdde482c072725dc524bd7743a81336cb 100755
--- a/indra/llcommon/llinitparam.h
+++ b/indra/llcommon/llinitparam.h
@@ -38,6 +38,7 @@
 #include "llerror.h"
 #include "llstl.h"
 #include "llpredicate.h"
+#include "llsd.h"
 
 namespace LLTypeTags
 {
diff --git a/indra/llcommon/llsdutil.h b/indra/llcommon/llsdutil.h
index 532d3f934139c5542617d163204d5727e47464aa..d0b536c39af64bf68379b7748ece61c6a6cfc164 100755
--- a/indra/llcommon/llsdutil.h
+++ b/indra/llcommon/llsdutil.h
@@ -29,7 +29,7 @@
 #ifndef LL_LLSDUTIL_H
 #define LL_LLSDUTIL_H
 
-class LLSD;
+#include "llsd.h"
 
 // U32
 LL_COMMON_API LLSD ll_sd_from_U32(const U32);
diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp
index 66c416bfdd26706c902a4d9a74f335a598c5aed7..6f92c7d5d4a470ebec559f6ae440879254dc8eae 100755
--- a/indra/llcommon/llstring.cpp
+++ b/indra/llcommon/llstring.cpp
@@ -29,6 +29,7 @@
 #include "llstring.h"
 #include "llerror.h"
 #include "llfasttimer.h"
+#include "llsd.h"
 
 #if LL_WINDOWS
 #include "llwin32headerslean.h"
diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h
index 17893c1910e735452b37b469dbef75f9940dfeaa..fdf9f3ce89471ad27b0c94fa70f71c9d64d08a11 100755
--- a/indra/llcommon/llstring.h
+++ b/indra/llcommon/llstring.h
@@ -29,10 +29,11 @@
 
 #include <string>
 #include <cstdio>
-#include <locale>
+//#include <locale>
 #include <iomanip>
 #include <algorithm>
-#include "llsd.h"
+#include <vector>
+#include <map>
 #include "llformat.h"
 
 #if LL_LINUX || LL_SOLARIS
@@ -50,6 +51,7 @@
 #endif
 
 const char LL_UNKNOWN_CHAR = '?';
+class LLSD;
 
 #if LL_DARWIN || LL_LINUX || LL_SOLARIS
 // Template specialization of char_traits for U16s. Only necessary on Mac and Linux (exists on Windows already)
diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp
index 5d805ba841899ebfdd4571368fe99e277f76f768..8d2045dfa0af0058b709c9b5d06d90a77f5fe38c 100755
--- a/indra/llcommon/llsys.cpp
+++ b/indra/llcommon/llsys.cpp
@@ -1396,13 +1396,13 @@ class FrameWatcher
                     << " seconds ";
         }
 
-		S32 precision = LL_CONT.precision();
+	S32 precision = LL_CONT.precision();
 
         LL_CONT << std::fixed << std::setprecision(1) << framerate << '\n'
                 << LLMemoryInfo();
 
-		LL_CONT.precision(precision);
-		LL_CONT << LL_ENDL;
+	LL_CONT.precision(precision);
+	LL_CONT << LL_ENDL;
         return false;
     }
 
diff --git a/indra/llcommon/lltraceaccumulators.h b/indra/llcommon/lltraceaccumulators.h
index a2f9f4c0906d073f624fbe97f728d6e84a19afc5..efc8b43f6aaedfec0985490990f9319e2c39b2e9 100644
--- a/indra/llcommon/lltraceaccumulators.h
+++ b/indra/llcommon/lltraceaccumulators.h
@@ -34,6 +34,7 @@
 #include "lltimer.h"
 #include "llrefcount.h"
 #include "llthreadlocalstorage.h"
+#include <limits>
 
 namespace LLTrace
 {
diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp
index 48b5a7c3fad4b217b6b8c979bee6e7b8aafd07e1..2150a44f1269eb7be889dd111d599e804a0bd56b 100644
--- a/indra/llcommon/lltracerecording.cpp
+++ b/indra/llcommon/lltracerecording.cpp
@@ -95,7 +95,7 @@ void Recording::handleReset()
 {
 	mBuffers.write()->reset();
 
-	mElapsedSeconds = 0.0;
+	mElapsedSeconds = LLUnits::Seconds::fromValue(0.0);
 	mSamplingTimer.reset();
 }
 
@@ -131,14 +131,14 @@ void Recording::appendRecording( Recording& other )
 LLUnit<F64, LLUnits::Seconds> Recording::getSum(const TraceType<TimeBlockAccumulator>& stat)
 {
 	const TimeBlockAccumulator& accumulator = mBuffers->mStackTimers[stat.getIndex()];
-	return (F64)(accumulator.mTotalTimeCounter - accumulator.mStartTotalTimeCounter) 
-				/ (F64)LLTrace::TimeBlock::countsPerSecond();
+	return LLUnits::Seconds::fromValue((F64)(accumulator.mTotalTimeCounter - accumulator.mStartTotalTimeCounter) 
+				/ (F64)LLTrace::TimeBlock::countsPerSecond());
 }
 
 LLUnit<F64, LLUnits::Seconds> Recording::getSum(const TraceType<TimeBlockAccumulator::SelfTimeFacet>& stat)
 {
 	const TimeBlockAccumulator& accumulator = mBuffers->mStackTimers[stat.getIndex()];
-	return (F64)(accumulator.mSelfTimeCounter) / (F64)LLTrace::TimeBlock::countsPerSecond();
+	return LLUnits::Seconds::fromValue((F64)(accumulator.mSelfTimeCounter) / (F64)LLTrace::TimeBlock::countsPerSecond());
 }
 
 
@@ -151,16 +151,16 @@ LLUnit<F64, LLUnits::Seconds> Recording::getPerSec(const TraceType<TimeBlockAccu
 {
 	const TimeBlockAccumulator& accumulator = mBuffers->mStackTimers[stat.getIndex()];
 
-	return (F64)(accumulator.mTotalTimeCounter - accumulator.mStartTotalTimeCounter) 
-				/ ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds.value());
+	return LLUnits::Seconds::fromValue((F64)(accumulator.mTotalTimeCounter - accumulator.mStartTotalTimeCounter) 
+				/ ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds.value()));
 }
 
 LLUnit<F64, LLUnits::Seconds> Recording::getPerSec(const TraceType<TimeBlockAccumulator::SelfTimeFacet>& stat)
 {
 	const TimeBlockAccumulator& accumulator = mBuffers->mStackTimers[stat.getIndex()];
 
-	return (F64)(accumulator.mSelfTimeCounter) 
-			/ ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds.value());
+	return LLUnits::Seconds::fromValue((F64)(accumulator.mSelfTimeCounter) 
+			/ ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds.value()));
 }
 
 F32 Recording::getPerSec(const TraceType<TimeBlockAccumulator::CallCountFacet>& stat)
@@ -170,52 +170,52 @@ F32 Recording::getPerSec(const TraceType<TimeBlockAccumulator::CallCountFacet>&
 
 LLUnit<F64, LLUnits::Bytes> Recording::getMin(const TraceType<MemStatAccumulator>& stat)
 {
-	return mBuffers->mMemStats[stat.getIndex()].mSize.getMin();
+	return LLUnits::Bytes::fromValue(mBuffers->mMemStats[stat.getIndex()].mSize.getMin());
 }
 
 LLUnit<F64, LLUnits::Bytes> Recording::getMean(const TraceType<MemStatAccumulator>& stat)
 {
-	return mBuffers->mMemStats[stat.getIndex()].mSize.getMean();
+	return LLUnits::Bytes::fromValue(mBuffers->mMemStats[stat.getIndex()].mSize.getMean());
 }
 
 LLUnit<F64, LLUnits::Bytes> Recording::getMax(const TraceType<MemStatAccumulator>& stat)
 {
-	return mBuffers->mMemStats[stat.getIndex()].mSize.getMax();
+	return LLUnits::Bytes::fromValue(mBuffers->mMemStats[stat.getIndex()].mSize.getMax());
 }
 
 LLUnit<F64, LLUnits::Bytes> Recording::getStandardDeviation(const TraceType<MemStatAccumulator>& stat)
 {
-	return mBuffers->mMemStats[stat.getIndex()].mSize.getStandardDeviation();
+	return LLUnits::Bytes::fromValue(mBuffers->mMemStats[stat.getIndex()].mSize.getStandardDeviation());
 }
 
 LLUnit<F64, LLUnits::Bytes> Recording::getLastValue(const TraceType<MemStatAccumulator>& stat)
 {
-	return mBuffers->mMemStats[stat.getIndex()].mSize.getLastValue();
+	return LLUnits::Bytes::fromValue(mBuffers->mMemStats[stat.getIndex()].mSize.getLastValue());
 }
 
 LLUnit<F64, LLUnits::Bytes> Recording::getMin(const TraceType<MemStatAccumulator::ChildMemFacet>& stat)
 {
-	return mBuffers->mMemStats[stat.getIndex()].mChildSize.getMin();
+	return LLUnits::Bytes::fromValue(mBuffers->mMemStats[stat.getIndex()].mChildSize.getMin());
 }
 
 LLUnit<F64, LLUnits::Bytes> Recording::getMean(const TraceType<MemStatAccumulator::ChildMemFacet>& stat)
 {
-	return mBuffers->mMemStats[stat.getIndex()].mChildSize.getMean();
+	return LLUnits::Bytes::fromValue(mBuffers->mMemStats[stat.getIndex()].mChildSize.getMean());
 }
 
 LLUnit<F64, LLUnits::Bytes> Recording::getMax(const TraceType<MemStatAccumulator::ChildMemFacet>& stat)
 {
-	return mBuffers->mMemStats[stat.getIndex()].mChildSize.getMax();
+	return LLUnits::Bytes::fromValue(mBuffers->mMemStats[stat.getIndex()].mChildSize.getMax());
 }
 
 LLUnit<F64, LLUnits::Bytes> Recording::getStandardDeviation(const TraceType<MemStatAccumulator::ChildMemFacet>& stat)
 {
-	return mBuffers->mMemStats[stat.getIndex()].mChildSize.getStandardDeviation();
+	return LLUnits::Bytes::fromValue(mBuffers->mMemStats[stat.getIndex()].mChildSize.getStandardDeviation());
 }
 
 LLUnit<F64, LLUnits::Bytes> Recording::getLastValue(const TraceType<MemStatAccumulator::ChildMemFacet>& stat)
 {
-	return mBuffers->mMemStats[stat.getIndex()].mChildSize.getLastValue();
+	return LLUnits::Bytes::fromValue(mBuffers->mMemStats[stat.getIndex()].mChildSize.getLastValue());
 }
 
 U32 Recording::getSum(const TraceType<MemStatAccumulator::AllocationCountFacet>& stat)
@@ -603,7 +603,7 @@ F64 PeriodicRecording::getPeriodMean( const TraceType<SampleAccumulator>& stat,
 	size_t total_periods = mRecordingPeriods.size();
 	num_periods = llmin(num_periods, isStarted() ? total_periods - 1 : total_periods);
 
-	LLUnit<F64, LLUnits::Seconds> total_duration = 0.f;
+	LLUnit<F64, LLUnits::Seconds> total_duration(0.f);
 
 	F64 mean = 0;
 	if (num_periods <= 0) { return mean; }
diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h
index 51f14a5948147f4fbf355b55cb9d891cf637d9c8..f81e746c77de1b68119475ea2fdc04c825d2e3dc 100644
--- a/indra/llcommon/llunit.h
+++ b/indra/llcommon/llunit.h
@@ -141,8 +141,17 @@ struct LLUnit
 template<typename STORAGE_TYPE, typename UNIT_TYPE>
 std::ostream& operator <<(std::ostream& s, const LLUnit<STORAGE_TYPE, UNIT_TYPE>& unit)
 {
-	s << unit.value() << UNIT_TYPE::getUnitLabel();
-	return s;
+        s << unit.value() << UNIT_TYPE::getUnitLabel();
+        return s;
+}
+
+template<typename STORAGE_TYPE, typename UNIT_TYPE>
+std::istream& operator >>(std::istream& s, LLUnit<STORAGE_TYPE, UNIT_TYPE>& unit)
+{
+        STORAGE_TYPE val;
+        s >> val;
+        unit = val;
+        return s;
 }
 
 template<typename STORAGE_TYPE, typename UNIT_TYPE>
@@ -172,8 +181,17 @@ struct LLUnitImplicit : public LLUnit<STORAGE_TYPE, UNIT_TYPE>
 template<typename STORAGE_TYPE, typename UNIT_TYPE>
 std::ostream& operator <<(std::ostream& s, const LLUnitImplicit<STORAGE_TYPE, UNIT_TYPE>& unit)
 {
-	s << unit.value() << UNIT_TYPE::getUnitLabel();
-	return s;
+        s << unit.value() << UNIT_TYPE::getUnitLabel();
+        return s;
+}
+
+template<typename STORAGE_TYPE, typename UNIT_TYPE>
+std::istream& operator >>(std::istream& s, LLUnitImplicit<STORAGE_TYPE, UNIT_TYPE>& unit)
+{
+        STORAGE_TYPE val;
+        s >> val;
+        unit = val;
+        return s;
 }
 
 template<typename S, typename T> 
@@ -201,7 +219,7 @@ LL_FORCE_INLINE void ll_convert_units(LLUnit<S1, T1> in, LLUnit<S2, T2>& out, ..
 
 		{
 			// T1 and T2 fully reduced and equal...just copy
-			out = (S2)in.value();
+			out = LLUnit<S2, T2>((S2)in.value());
 		}
 		else
 		{
@@ -447,33 +465,33 @@ template<typename VALUE_TYPE>
 struct LLUnitLinearOps
 {
 	typedef LLUnitLinearOps<VALUE_TYPE> self_t;
-	LLUnitLinearOps(VALUE_TYPE val) : mValue (val) {}
+	LLUnitLinearOps(VALUE_TYPE val) : mResult (val) {}
 
-	operator VALUE_TYPE() const { return mValue; }
-	VALUE_TYPE mValue;
+	operator VALUE_TYPE() const { return mResult; }
+	VALUE_TYPE mResult;
 
 	template<typename T>
 	self_t operator * (T other)
 	{
-		return mValue * other;
+		return mResult * other;
 	}
 
 	template<typename T>
 	self_t operator / (T other)
 	{
-		return mValue / other;
+		return mResult / other;
 	}
 
 	template<typename T>
 	self_t operator + (T other)
 	{
-		return mValue + other;
+		return mResult + other;
 	}
 
 	template<typename T>
 	self_t operator - (T other)
 	{
-		return mValue - other;
+		return mResult - other;
 	}
 };
 
@@ -482,32 +500,32 @@ struct LLUnitInverseLinearOps
 {
 	typedef LLUnitInverseLinearOps<VALUE_TYPE> self_t;
 
-	LLUnitInverseLinearOps(VALUE_TYPE val) : mValue (val) {}
-	operator VALUE_TYPE() const { return mValue; }
-	VALUE_TYPE mValue;
+	LLUnitInverseLinearOps(VALUE_TYPE val) : mResult (val) {}
+	operator VALUE_TYPE() const { return mResult; }
+	VALUE_TYPE mResult;
 
 	template<typename T>
 	self_t operator * (T other)
 	{
-		return mValue / other;
+		return mResult / other;
 	}
 
 	template<typename T>
 	self_t operator / (T other)
 	{
-		return mValue * other;
+		return mResult * other;
 	}
 
 	template<typename T>
 	self_t operator + (T other)
 	{
-		return mValue - other;
+		return mResult - other;
 	}
 
 	template<typename T>
 	self_t operator - (T other)
 	{
-		return mValue + other;
+		return mResult + other;
 	}
 };
 
@@ -521,35 +539,31 @@ struct base_unit_name
 	template<typename STORAGE_T, typename UNIT_T>                                                    \
 	static LLUnit<STORAGE_T, base_unit_name> fromValue(LLUnit<STORAGE_T, UNIT_T> value)              \
 	{ return LLUnit<STORAGE_T, base_unit_name>(value); }                                             \
-};                                                                                                   \
-template<typename T> std::ostream& operator<<(std::ostream& s, const LLUnit<T, base_unit_name>& val) \
-{ s << val.value() << base_unit_name::getUnitLabel; return s; }
-
-
-#define LL_DECLARE_DERIVED_UNIT(unit_name, unit_label, base_unit_name, conversion_operation)	 \
-struct unit_name                                                                                 \
-{                                                                                                \
-	typedef base_unit_name base_unit_t;                                                          \
-	static const char* getUnitLabel() { return unit_label; }									 \
-	template<typename T>                                                                         \
-	static LLUnit<T, unit_name> fromValue(T value) { return LLUnit<T, unit_name>(value); }		 \
-	template<typename STORAGE_T, typename UNIT_T>                                                \
-	static LLUnit<STORAGE_T, unit_name> fromValue(LLUnit<STORAGE_T, UNIT_T> value)				 \
-	{ return LLUnit<STORAGE_T, unit_name>(value); }												 \
-};                                                                                               \
-template<typename T> std::ostream& operator<<(std::ostream& s, const LLUnit<T, unit_name>& val)  \
-{ s << val.value() << unit_name::getUnitLabel; return s; }                                       \
-	                                                                                             \
-template<typename S1, typename S2>                                                               \
-void ll_convert_units(LLUnit<S1, unit_name> in, LLUnit<S2, base_unit_name>& out)                 \
-{                                                                                                \
-	out = (S2)(LLUnitLinearOps<S1>(in.value()) conversion_operation).mValue;                     \
-}                                                                                                \
-                                                                                                 \
-template<typename S1, typename S2>                                                               \
-void ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, unit_name>& out)                 \
-{                                                                                                \
-	out = (S2)(LLUnitInverseLinearOps<S1>(in.value()) conversion_operation).mValue;              \
+}
+
+
+#define LL_DECLARE_DERIVED_UNIT(unit_name, unit_label, base_unit_name, conversion_operation)	    \
+struct unit_name                                                                                    \
+{                                                                                                   \
+	typedef base_unit_name base_unit_t;                                                             \
+	static const char* getUnitLabel() { return unit_label; }									    \
+	template<typename T>                                                                            \
+	static LLUnit<T, unit_name> fromValue(T value) { return LLUnit<T, unit_name>(value); }		    \
+	template<typename STORAGE_T, typename UNIT_T>                                                   \
+	static LLUnit<STORAGE_T, unit_name> fromValue(LLUnit<STORAGE_T, UNIT_T> value)				    \
+	{ return LLUnit<STORAGE_T, unit_name>(value); }												    \
+};                                                                                                  \
+	                                                                                                \
+template<typename S1, typename S2>                                                                  \
+void ll_convert_units(LLUnit<S1, unit_name> in, LLUnit<S2, base_unit_name>& out)                    \
+{                                                                                                   \
+	out = LLUnit<S2, base_unit_name>((S2)(LLUnitLinearOps<S1>(in.value()) conversion_operation));   \
+}                                                                                                   \
+                                                                                                    \
+template<typename S1, typename S2>                                                                  \
+void ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, unit_name>& out)                    \
+{                                                                                                   \
+	out = LLUnit<S2, unit_name>((S2)(LLUnitInverseLinearOps<S1>(in.value()) conversion_operation)); \
 }                                                                                               
 
 //
diff --git a/indra/llcommon/lluuid.h b/indra/llcommon/lluuid.h
index 7889828c85144422d57f725d3946b5fcfc56383d..0699dcda83b8d66851278b3436bf6fc287d45506 100755
--- a/indra/llcommon/lluuid.h
+++ b/indra/llcommon/lluuid.h
@@ -28,6 +28,7 @@
 
 #include <iostream>
 #include <set>
+#include <vector>
 #include "stdtypes.h"
 #include "llpreprocessor.h"
 
diff --git a/indra/llimage/llimagej2c.cpp b/indra/llimage/llimagej2c.cpp
index 65cdcd6923a176a575d5c32d0dda7aedc250781a..8e2bcc3f9434eb0cb51172f7d52380d1d86c4511 100755
--- a/indra/llimage/llimagej2c.cpp
+++ b/indra/llimage/llimagej2c.cpp
@@ -30,6 +30,7 @@
 #include "lltimer.h"
 #include "llmath.h"
 #include "llmemory.h"
+#include "llsd.h"
 
 typedef LLImageJ2CImpl* (*CreateLLImageJ2CFunction)();
 typedef void (*DestroyLLImageJ2CFunction)(LLImageJ2CImpl*);
diff --git a/indra/llmath/llcalcparser.h b/indra/llmath/llcalcparser.h
index e0ad270266eb2b742697344d4d25976f53f580b2..faa699ff7b609b862dfbeeeba288ef1b59e36b53 100755
--- a/indra/llmath/llcalcparser.h
+++ b/indra/llmath/llcalcparser.h
@@ -163,7 +163,7 @@ struct LLCalcParser : grammar<LLCalcParser>
 	
 	bool checkNaN(const F32& a) const { return !llisnan(a); }
 	
-	//FIX* non ambigious function fix making SIN() work for calc -Cryogenic Blitz
+	//FIX* non ambiguous function fix making SIN() work for calc -Cryogenic Blitz
 	F32 _sin(const F32& a) const { return sin(DEG_TO_RAD * a); }
 	F32 _cos(const F32& a) const { return cos(DEG_TO_RAD * a); }
 	F32 _tan(const F32& a) const { return tan(DEG_TO_RAD * a); }
@@ -176,11 +176,8 @@ struct LLCalcParser : grammar<LLCalcParser>
 	F32 _fabs(const F32& a) const { return fabs(a); }
 	F32 _floor(const F32& a) const { return (F32)llfloor(a); }
 	F32 _ceil(const F32& a) const { return llceil(a); }
-
 	F32 _atan2(const F32& a,const F32& b) const { return atan2(a,b); }
 
-
-
 	LLCalc::calc_map_t* mConstants;
 	LLCalc::calc_map_t* mVariables;
 //	LLCalc::calc_map_t* mUserVariables;
diff --git a/indra/llprimitive/llmaterialid.h b/indra/llprimitive/llmaterialid.h
index 0a952040859625b2846e846001ea4be699a44093..b4c82d3b7b7fc0c21d0a8f9d1f265539c7852877 100644
--- a/indra/llprimitive/llmaterialid.h
+++ b/indra/llprimitive/llmaterialid.h
@@ -30,6 +30,7 @@
 #define MATERIAL_ID_SIZE 16
 
 #include <string>
+#include "llsd.h"
 
 class LLMaterialID
 {
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 01ed946d4015e31712c5c26f645b4b2ded0cb962..1d4be1f53cd96b1c844f99680451e57d034ca583 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -51,9 +51,9 @@ U32 wpo2(U32 i);
 
 U32 LLImageGL::sUniqueCount				= 0;
 U32 LLImageGL::sBindCount				= 0;
-LLUnit<S32, LLUnits::Bytes> LLImageGL::sGlobalTextureMemory		= 0;
-LLUnit<S32, LLUnits::Bytes> LLImageGL::sBoundTextureMemory		= 0;
-LLUnit<S32, LLUnits::Bytes> LLImageGL::sCurBoundTextureMemory	= 0;
+LLUnit<S32, LLUnits::Bytes> LLImageGL::sGlobalTextureMemory(0);
+LLUnit<S32, LLUnits::Bytes> LLImageGL::sBoundTextureMemory(0);
+LLUnit<S32, LLUnits::Bytes> LLImageGL::sCurBoundTextureMemory(0);
 S32 LLImageGL::sCount					= 0;
 LLImageGL::dead_texturelist_t LLImageGL::sDeadTextureList[LLTexUnit::TT_NONE];
 U32 LLImageGL::sCurTexName = 1;
@@ -249,7 +249,7 @@ void LLImageGL::updateStats(F32 current_time)
 	LLFastTimer t(FTM_IMAGE_UPDATE_STATS);
 	sLastFrameTime = current_time;
 	sBoundTextureMemory = sCurBoundTextureMemory;
-	sCurBoundTextureMemory = 0;
+	sCurBoundTextureMemory = LLUnits::Bytes::fromValue(0);
 }
 
 //static
diff --git a/indra/llui/llnotificationsutil.h b/indra/llui/llnotificationsutil.h
index 4093324d0c38ab23301f370a3dfd1735f76a7eab..9f29087b4a8f6c9980be2c4d26270b2b135858c2 100755
--- a/indra/llui/llnotificationsutil.h
+++ b/indra/llui/llnotificationsutil.h
@@ -30,6 +30,7 @@
 // to avoid including the heavyweight llnotifications.h
 
 #include "llnotificationptr.h"
+#include "lluuid.h"
 
 #include <boost/function.hpp>
 
diff --git a/indra/llui/lltrans.h b/indra/llui/lltrans.h
index 128b51d3831dcd70f0c9a97edf1e93cebc41004d..a47ce94f080658d5d0b0ce4cfe8123c6f274f820 100755
--- a/indra/llui/lltrans.h
+++ b/indra/llui/lltrans.h
@@ -28,6 +28,7 @@
 #define LL_TRANS_H
 
 #include <map>
+#include <set>
 
 #include "llpointer.h"
 #include "llstring.h"
diff --git a/indra/llxml/llxmlnode.h b/indra/llxml/llxmlnode.h
index d7681c54a0dbb14a73edca7257cdbc900165d7a2..f7c32c4cf5707bf410eca42159896069cdc773c7 100755
--- a/indra/llxml/llxmlnode.h
+++ b/indra/llxml/llxmlnode.h
@@ -42,12 +42,11 @@
 #include "llstring.h"
 #include "llstringtable.h"
 #include "llfile.h"
-
+#include "lluuid.h"
 
 class LLVector3;
 class LLVector3d;
 class LLQuaternion;
-class LLUUID;
 class LLColor4;
 class LLColor4U;
 
diff --git a/indra/newview/llscenemonitor.cpp b/indra/newview/llscenemonitor.cpp
index 3f4f8721745fe93f67deaed072db8a9f42c911d5..29dd140158de5f4e5e7575b9973c7bf70c050496 100644
--- a/indra/newview/llscenemonitor.cpp
+++ b/indra/newview/llscenemonitor.cpp
@@ -89,6 +89,7 @@ void LLSceneMonitor::reset()
 
 	mMonitorRecording.reset();
 	mSceneLoadRecording.reset();
+	mRecordingTimer.reset();
 
 	unfreezeScene();
 
@@ -259,7 +260,6 @@ void LLSceneMonitor::capture()
 	static U32 last_capture_frame = 0;
 	static LLCachedControl<bool> monitor_enabled(gSavedSettings, "SceneLoadingMonitorEnabled");
 	static LLCachedControl<F32>  scene_load_sample_time(gSavedSettings, "SceneLoadingMonitorSampleTime");
-	static LLFrameTimer timer;	
 	static bool force_capture = true;
 
 	bool enabled = monitor_enabled || mDebugViewerVisible;
@@ -288,7 +288,7 @@ void LLSceneMonitor::capture()
 		force_capture = true;
 	}
 
-	if((timer.getElapsedTimeF32() > scene_load_sample_time() 
+	if((mRecordingTimer.getElapsedTimeF32() > scene_load_sample_time() 
 			|| force_capture)
 		&& mEnabled
 		&& LLGLSLShader::sNoFixedFunction
@@ -299,8 +299,6 @@ void LLSceneMonitor::capture()
 		mSceneLoadRecording.resume();
 		mMonitorRecording.resume();
 
-		timer.reset();
-
 		last_capture_frame = gFrameCount;
 
 		LLRenderTarget& cur_target = getCaptureTarget();
@@ -467,7 +465,6 @@ void LLSceneMonitor::fetchQueryResult()
 
 	// also throttle timing here, to avoid going below sample time due to phasing with frame capture
 	static LLCachedControl<F32>  scene_load_sample_time(gSavedSettings, "SceneLoadingMonitorSampleTime");
-	static LLFrameTimer timer;	
 
 	if(mDiffState == WAIT_ON_RESULT 
 		&& !LLAppViewer::instance()->quitRequested())
@@ -483,11 +480,11 @@ void LLSceneMonitor::fetchQueryResult()
 	
 			mDiffResult = sqrtf(count * 0.5f / (mDiff->getWidth() * mDiff->getHeight() * mDiffPixelRatio * mDiffPixelRatio)); //0.5 -> (front face + back face)
 
-			LL_DEBUGS("SceneMonitor") << "Frame difference: " << std::setprecision(4) << mDiffResult << LL_ENDL;
+			LL_DEBUGS("SceneMonitor") << "Frame difference: " << mDiffResult << LL_ENDL;
 			record(sFramePixelDiff, mDiffResult);
 
 			static LLCachedControl<F32> diff_threshold(gSavedSettings,"SceneLoadingPixelDiffThreshold");
-			F32 elapsed_time = timer.getElapsedTimeF32();
+			F32 elapsed_time = mRecordingTimer.getElapsedTimeF32();
 
 			if (elapsed_time > scene_load_sample_time)
 			{
@@ -501,10 +498,9 @@ void LLSceneMonitor::fetchQueryResult()
 				{
 					mSceneLoadRecording.nextPeriod();
 				}
+				mRecordingTimer.reset();
 			}
 		}
-
-		timer.reset();
 	}
 }
 
diff --git a/indra/newview/llscenemonitor.h b/indra/newview/llscenemonitor.h
index 7088d529d6ec4d13e5ab3d9f5ff662244c8167e7..b857389243c0c3356ed37622c99eb11bd5cccd8c 100644
--- a/indra/newview/llscenemonitor.h
+++ b/indra/newview/llscenemonitor.h
@@ -72,8 +72,8 @@ class LLSceneMonitor : public LLSingleton<LLSceneMonitor>
 	void generateDitheringTexture(S32 width, S32 height);
 
 private:
-	bool mEnabled;
-	bool mDebugViewerVisible;
+	bool									mEnabled,
+											mDebugViewerVisible;
 
 	enum EDiffState
 	{
@@ -82,27 +82,27 @@ class LLSceneMonitor : public LLSingleton<LLSceneMonitor>
 		EXECUTE_DIFF,
 		WAIT_ON_RESULT,
 		VIEWER_QUITTING
-	}	mDiffState;
+	}										mDiffState;
 
-	LLRenderTarget* mFrames[2];
-	LLRenderTarget* mDiff;
+	LLRenderTarget*							mFrames[2];
+	LLRenderTarget*							mDiff;
 
-	GLuint  mQueryObject; //used for glQuery
-	F32     mDiffResult;  //aggregate results of mDiff.
-	F32     mDiffTolerance; //pixels are filtered out when R+G+B < mDiffTolerance
+	GLuint									mQueryObject; //used for glQuery
+	F32										mDiffResult,  //aggregate results of mDiff.
+											mDiffTolerance, //pixels are filtered out when R+G+B < mDiffTolerance
+											mDiffPixelRatio; //ratio of pixels used for comparison against the original mDiff size along one dimension
 
-	F32     mDiffPixelRatio; //ratio of pixels used for comparison against the original mDiff size along one dimension
+	LLPointer<LLViewerTexture>				mDitheringTexture;
+	S32										mDitherMatrixWidth;
+	F32										mDitherScale,
+											mDitherScaleS,
+											mDitherScaleT;
 
-	LLPointer<LLViewerTexture> mDitheringTexture;
-	S32                        mDitherMatrixWidth;
-	F32                        mDitherScale;
-	F32                        mDitherScaleS;
-	F32                        mDitherScaleT;
+	std::vector<LLAnimPauseRequest>			mAvatarPauseHandles;
 
-	std::vector<LLAnimPauseRequest> mAvatarPauseHandles;
-
-	LLTrace::ExtendablePeriodicRecording mSceneLoadRecording;
-	LLTrace::Recording					 mMonitorRecording;
+	LLFrameTimer							mRecordingTimer;
+	LLTrace::ExtendablePeriodicRecording	mSceneLoadRecording;
+	LLTrace::Recording						mMonitorRecording;
 };
 
 class LLSceneMonitorView : public LLFloater