diff --git a/indra/cmake/00-Common.cmake b/indra/cmake/00-Common.cmake
index 21cb87237ddf312ecd31ca2ff0ee36945c58ee37..180714c9c9c182ae694f9b36b2425ee83c6b782c 100644
--- a/indra/cmake/00-Common.cmake
+++ b/indra/cmake/00-Common.cmake
@@ -58,6 +58,7 @@ if (WINDOWS)
 
   add_definitions(
       /DLL_WINDOWS=1
+      /DNOMINMAX
       /DDOM_DYNAMIC
       /DUNICODE
       /D_UNICODE 
diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h
index c77d96c1c9c29f19479a6764c6e9d01523c0a598..d9fe257e8656feb758e262b4075f8a187b8c0ac2 100644
--- a/indra/llcommon/llapr.h
+++ b/indra/llcommon/llapr.h
@@ -40,6 +40,7 @@
 #include "apr_getopt.h"
 #include "apr_signal.h"
 #include "apr_atomic.h"
+
 #include "llstring.h"
 #include "llinstancetracker.h"
 
diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp
index d007f76e5ff6221a2af10ea6d60256c697005c06..4ecca12832d7382139cea4aaf282cf6d81944bca 100644
--- a/indra/llcommon/llfasttimer.cpp
+++ b/indra/llcommon/llfasttimer.cpp
@@ -121,6 +121,11 @@ void BlockTimer::pushLog(LLSD log)
 	sLogQueue.push(log);
 }
 
+void BlockTimer::setLogLock(LLMutex* lock)
+{
+	sLogLock = lock;
+}
+
 
 //static
 #if (LL_DARWIN || LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__))
diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h
index 69a6773b12f73c366a41d6cd5ac190ccaaf0bbe4..af9b360e01eb12fa911cce373a7709d85bbc6f78 100644
--- a/indra/llcommon/llfasttimer.h
+++ b/indra/llcommon/llfasttimer.h
@@ -98,6 +98,7 @@ class BlockTimer
 
 	static BlockTimer& getRootTimer();
 	static void pushLog(LLSD sd);
+	static void setLogLock(LLMutex* mutex);
 	friend class Time;
 
 
@@ -329,6 +330,6 @@ LL_FORCE_INLINE Time::~Time()
 
 }
 
-typedef LLTrace::Time LLFastTimer;
+typedef LLTrace::Time LLFastTimer; 
 
 #endif // LL_LLFASTTIMER_H
diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h
index 82ab5f47d2d67c9cfd584595366ca2d78692a351..93c752754db221618b096a731ceabd7ad1a77125 100644
--- a/indra/llcommon/llthread.h
+++ b/indra/llcommon/llthread.h
@@ -32,6 +32,8 @@
 #include "apr_thread_cond.h"
 #include "llmutex.h"
 
+LL_COMMON_API void assert_main_thread();
+
 class LL_COMMON_API LLThread
 {
 private:
diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp
index 9346aa7a45ca98a38ea73e3d3feb5f2d858f4f34..9bf9ae6c8e2cc2fbf3e0796c51c1b669d3f5db93 100644
--- a/indra/llcommon/lltrace.cpp
+++ b/indra/llcommon/lltrace.cpp
@@ -59,7 +59,6 @@ LLThreadLocalPointer<ThreadRecorder>& get_thread_recorder()
 {
 	static LLThreadLocalPointer<ThreadRecorder> s_thread_recorder;
 	return s_thread_recorder;
-
 }
 
 }
diff --git a/indra/llcommon/llwin32headers.h b/indra/llcommon/llwin32headers.h
index 80fd2e1768e793b2cca7fda88af5f7701f7e4be6..9c89b6b280fabd309041a2cb7fc1a134fac802f2 100644
--- a/indra/llcommon/llwin32headers.h
+++ b/indra/llcommon/llwin32headers.h
@@ -28,11 +28,9 @@
 #define LL_LLWINDOWS_H
 
 #ifdef LL_WINDOWS
-#define NOMINMAX
 #undef WIN32_LEAN_AND_MEAN
 #include <winsock2.h>
 #include <windows.h>
-#undef NOMINMAX
 #endif
 
 #endif
diff --git a/indra/llcommon/llwin32headerslean.h b/indra/llcommon/llwin32headerslean.h
index ab6e9c09e26d3b6d1d401fdbc1dceff1bb56f776..d3fb90d4b1814c4a3624bf2d1e42aebff45dfa02 100644
--- a/indra/llcommon/llwin32headerslean.h
+++ b/indra/llcommon/llwin32headerslean.h
@@ -28,7 +28,6 @@
 #define LL_LLWINDOWS_H
 
 #ifdef LL_WINDOWS
-#define NOMINMAX
 #define WIN32_LEAN_AND_MEAN
 #include <winsock2.h>
 #include <windows.h>
diff --git a/indra/llmessage/lliopipe.h b/indra/llmessage/lliopipe.h
index cbd17b5a3d9ba02be6430d051eecaaba6f8f571d..9a0a427efd0b9654f2ed66c7daea9acc0264bfd9 100644
--- a/indra/llmessage/lliopipe.h
+++ b/indra/llmessage/lliopipe.h
@@ -31,6 +31,7 @@
 
 #include <boost/intrusive_ptr.hpp>
 #include <boost/shared_ptr.hpp>
+#include "llwin32headerslean.h"
 #include "apr_poll.h"
 
 #include "llsd.h"
diff --git a/indra/llmessage/lliosocket.h b/indra/llmessage/lliosocket.h
index 4e07963af85151f5b4a56853624e292272adcc16..ec998552d02f7e71540b9afa4f7788ac61296cb3 100644
--- a/indra/llmessage/lliosocket.h
+++ b/indra/llmessage/lliosocket.h
@@ -38,8 +38,8 @@
  */
 
 #include "lliopipe.h"
-#include "apr_pools.h"
 #include "llwin32headerslean.h"
+#include "apr_pools.h"
 #include "apr_network_io.h"
 #include "llchainio.h"
 
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index c6ed8d5071cfd034f214eeabdbd9b02081045a0a..9d4ed833b82efef91f185f7e5c1df93da0cfe6b6 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -2033,7 +2033,7 @@ bool LLAppViewer::initThreads()
 
 	if (LLTrace::BlockTimer::sLog || LLTrace::BlockTimer::sMetricLog)
 	{
-		LLTrace::BlockTimer::sLogLock = new LLMutex(NULL);
+		LLTrace::BlockTimer::setLogLock(new LLMutex(NULL));
 		mFastTimerLogThread = new LLFastTimerLogThread(LLTrace::BlockTimer::sLogName);
 		mFastTimerLogThread->start();
 	}
diff --git a/indra/newview/llfasttimerview.cpp b/indra/newview/llfasttimerview.cpp
index d0bb75225c3a7f9429a4092269a58dfc859335c9..7a5c9dba46cd96b1a953edd72ad4e4b57441a480 100644
--- a/indra/newview/llfasttimerview.cpp
+++ b/indra/newview/llfasttimerview.cpp
@@ -92,7 +92,7 @@ LLFastTimerView::LLFastTimerView(const LLSD& key)
 	mScrollIndex = 0;
 	mHoverID = NULL;
 	mHoverBarIndex = -1;
-	FTV_NUM_TIMERS = LLTrace::BlockTimer::instanceCount();
+	FTV_NUM_TIMERS = LLInstanceTracker<LLTrace::BlockTimer>::instanceCount();
 	mPrintStats = -1;	
 }
 
@@ -235,7 +235,7 @@ BOOL LLFastTimerView::handleHover(S32 x, S32 y, MASK mask)
 
 	if(LLTrace::BlockTimer::sPauseHistory && mBarRect.pointInRect(x, y))
 	{
-		mHoverBarIndex = llmin(LLFastTimer::getCurFrameIndex() - 1, 
+		mHoverBarIndex = llmin(LLTrace::BlockTimer::getCurFrameIndex() - 1, 
 								MAX_VISIBLE_HISTORY - ((y - mBarRect.mBottom) * (MAX_VISIBLE_HISTORY + 2) / mBarRect.getHeight()));
 		if (mHoverBarIndex == 0)
 		{
@@ -292,7 +292,7 @@ BOOL LLFastTimerView::handleHover(S32 x, S32 y, MASK mask)
 
 static std::string get_tooltip(LLTrace::BlockTimer& timer, S32 history_index = -1)
 {
-	F64 ms_multiplier = 1000.0 / (F64)LLFastTimer::countsPerSecond();
+	F64 ms_multiplier = 1000.0 / (F64)LLTrace::BlockTimer::countsPerSecond();
 
 	std::string tooltip;
 	if (history_index < 0)
@@ -364,7 +364,7 @@ void LLFastTimerView::draw()
 	
 	std::string tdesc;
 
-	F64 clock_freq = (F64)LLFastTimer::countsPerSecond();
+	F64 clock_freq = (F64)LLTrace::BlockTimer::countsPerSecond();
 	F64 iclock_freq = 1000.0 / clock_freq;
 	
 	S32 margin = 10;
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp
index a071f338bac5333dc55165d6b5643e9654a9018d..a5e3cd404d76e20a51dee8eec4ff1db8cf8f8fdf 100755
--- a/indra/newview/llfloatermodelpreview.cpp
+++ b/indra/newview/llfloatermodelpreview.cpp
@@ -113,8 +113,6 @@
 #include "llviewernetwork.h"
 #include "llviewershadermgr.h"
 #include "glod/glod.h"
-#include <boost/algorithm/string.hpp>
-
 
 const S32 SLM_SUPPORTED_VERSION = 3;
 
diff --git a/indra/newview/llviewerstatsrecorder.h b/indra/newview/llviewerstatsrecorder.h
index ce6dd63ec564ae22f0a49d7184bc5fe4694f25b7..d1744f4910d66eaac242ca3af0d3033988260b4f 100644
--- a/indra/newview/llviewerstatsrecorder.h
+++ b/indra/newview/llviewerstatsrecorder.h
@@ -32,7 +32,7 @@
 // for analysis.
 
 // This is normally 0.  Set to 1 to enable viewer stats recording
-#define LL_RECORD_VIEWER_STATS	1
+#define LL_RECORD_VIEWER_STATS	0
 
 
 #include "llframetimer.h"
diff --git a/indra/newview/llxmlrpctransaction.cpp b/indra/newview/llxmlrpctransaction.cpp
index 0da70d398b06ca0b35e50a7c40cc737b3efa1491..583196fb7a609b26b7a08c5fc78ed8bf661600b5 100644
--- a/indra/newview/llxmlrpctransaction.cpp
+++ b/indra/newview/llxmlrpctransaction.cpp
@@ -25,6 +25,8 @@
  */
 
 #include "llviewerprecompiledheaders.h"
+// include this to get winsock2 because openssl attempts to include winsock1
+#include "llwin32headerslean.h"
 #include <openssl/x509_vfy.h>
 #include <openssl/ssl.h>
 #include "llsecapi.h"
diff --git a/indra/test/test.cpp b/indra/test/test.cpp
index 2b66c6aa2650fa83eb85e7e99fbbd214811d18d5..8bd302ce7a9a9eb9967bc8b9f7d7ddfb40c118bb 100644
--- a/indra/test/test.cpp
+++ b/indra/test/test.cpp
@@ -40,6 +40,7 @@
 #include "tests/wrapllerrs.h"             // RecorderProxy
 #include "stringize.h"
 #include "namedtempfile.h"
+#include "lltrace.h"
 
 #include "apr_pools.h"
 #include "apr_getopt.h"
@@ -513,7 +514,8 @@ int main(int argc, char **argv)
 #endif
 
 	ll_init_apr();
-
+	LLTrace::init();
+	
 	apr_getopt_t* os = NULL;
 	if(APR_SUCCESS != apr_getopt_init(&os, gAPRPoolp, argc, argv))
 	{