diff --git a/NIF_IO.h b/NIF_IO.h
index 7ed180158d3355f5d7d428694111565e9033a2c1..ca8d5f33305b9d660273baedf4171b3158625a40 100644
--- a/NIF_IO.h
+++ b/NIF_IO.h
@@ -440,7 +440,7 @@ void NifStream( vector<T> const & val, ostream& file, uint version = 0 ) {
 
 template <class T>
 void NifStream( vector<Key<T> > & val, istream& file, uint version, uint attr_arg ) {
-	vector<Key<T> >::iterator it;
+	typename vector<Key<T> >::iterator it;
 	for ( it = val.begin(); it != val.end(); ++it ) {
 		NifStream( *it, file, version, attr_arg );
 	}
@@ -448,7 +448,7 @@ void NifStream( vector<Key<T> > & val, istream& file, uint version, uint attr_ar
 
 template <class T>
 void NifStream( vector<Key<T> > const & val, ostream& file, uint version, uint attr_arg ) {
-	vector<Key<T> >::const_iterator it;
+	typename vector<Key<T> >::const_iterator it;
 	for ( it = val.begin(); it != val.end(); ++it ) {
 		NifStream( *it, file, version, attr_arg );
 	}
diff --git a/nif_math.h b/nif_math.h
index 70575852e31adcb115aa2b3964fefb7d9ba73678..2397d9302359be142ce98a3343c664cf1b7a32a1 100644
--- a/nif_math.h
+++ b/nif_math.h
@@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. */
 
 #include <cmath>
 #include <iostream>
+#include <stdexcept>
 
 using namespace std;
 
diff --git a/niflib.cpp b/niflib.cpp
index 679358c30e3cbfedb16ee9c7e0be13e795741acf..acd799a4468e8869439ac7ec659be47d119f1f56 100644
--- a/niflib.cpp
+++ b/niflib.cpp
@@ -814,7 +814,7 @@ void MergeSceneGraph( map<string,NiAVObjectRef> & name_map, const NiAVObjectRef
 		//par_par->GetAttr("Children")->RemoveLinks( par );
 
 		//Get the block to attatch to
-		NiObjectRef attatch = name_map[par_par->name];
+		NiObjectRef attatch = DynamicCast<NiObject>(name_map[par_par->name]);
 
 		//TODO:  Implement children
 		////Add this block as new child