Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision d1caa6c7aa23cd5f9211381edb88cec622650e22)
+++ src/GenPoly/Box.cc	(revision 0531b5db61ded49c008b780fc360790094f08601)
@@ -115,39 +115,29 @@
 			/// Wraps value for a specific (Key, TypeList) combination
 			typedef std::pair< TypeList, Value* > Instantiation;
-			/// Map of keys to instantiations of them
-			typedef std::map< Key*, std::vector< Instantiation > > Scope;
-
-			std::vector< Scope > scopes;  ///< list of scopes, from outermost to innermost
+			/// List of TypeLists paired with their appropriate values
+			typedef std::vector< Instantiation > ValueList;
+			/// Underlying map type; maps keys to a linear list of corresponding TypeLists and values
+			typedef ScopedMap< Key*, std::vector< Instantiation > > InnerMap;
+
+			InnerMap instantiations;  ///< instantiations
 
 		public:
 			/// Starts a new scope
-			void beginScope() {
-				Scope scope;
-				scopes.push_back(scope);
-			}
+			void beginScope() { instantiations.beginScope(); }
 
 			/// Ends a scope
-			void endScope() {
-				scopes.pop_back();
-			}
-
-			/// Default constructor initializes with one scope
-			InstantiationMap() { beginScope(); }
+			void endScope() { instantiations.endScope(); }
 
 			/// Gets the value for the (key, typeList) pair, returns NULL on none such.
-			Value *lookup( Key *key, const std::list< TypeExpr* >& params ) {
-				TypeList typeList( params );
-				
-				// scan scopes from innermost out
-				for ( typename std::vector< Scope >::const_reverse_iterator scope = scopes.rbegin(); scope != scopes.rend(); ++scope ) {
-					// skip scope if nothing for this key
-					typename Scope::const_iterator insts = scope->find( key );
-					if ( insts == scope->end() ) continue;
-					// look through instantiations for matches to typeList
-					for ( typename std::vector< Instantiation >::const_iterator inst = insts->second.begin(); inst != insts->second.end(); ++inst ) {
+			Value *lookup( Key *key, const std::list< TypeExpr* >& params ) const {
+ 				TypeList typeList( params );
+ 				
+				// scan scopes for matches to the key
+				for ( typename InnerMap::const_iterator insts = instantiations.find( key ); insts != instantiations.end(); insts = instantiations.findNext( insts, key ) ) {
+					for ( typename ValueList::const_reverse_iterator inst = insts->second.rbegin(); inst != insts->second.rend(); ++inst ) {
 						if ( inst->first == typeList ) return inst->second;
 					}
 				}
-				// no matching instantiation found
+				// no matching instantiations found
 				return 0;
 			}
@@ -155,5 +145,5 @@
 			/// Adds a value for a (key, typeList) pair to the current scope
 			void insert( Key *key, const std::list< TypeExpr* > &params, Value *value ) {
-				scopes.back()[key].push_back( Instantiation( TypeList( params ), value ) );
+				instantiations[ key ].push_back( Instantiation( TypeList( params ), value ) );
 			}
 		};
Index: src/GenPoly/ScopedMap.h
===================================================================
--- src/GenPoly/ScopedMap.h	(revision d1caa6c7aa23cd5f9211381edb88cec622650e22)
+++ src/GenPoly/ScopedMap.h	(revision 0531b5db61ded49c008b780fc360790094f08601)
@@ -17,4 +17,5 @@
 #define _SCOPEDMAP_H
 
+#include <cassert>
 #include <iterator>
 #include <map>
@@ -164,4 +165,5 @@
 		void endScope() {
 			scopes.pop_back();
+			assert( ! scopes.empty() );
 		}
 
@@ -188,5 +190,7 @@
 			return end();
 		}
-		const_iterator find( const Key &key ) const { return const_iterator( find( key ) ); }
+		const_iterator find( const Key &key ) const {
+				return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->find( key ) );
+		}
 		
 		/// Finds the given key in the outermost scope inside the given scope where it occurs
@@ -200,5 +204,7 @@
 			return end();
 		}
-		const_iterator findNext( const_iterator &it, const Key &key ) const { return const_iterator( findNext( it, key ) ); }
+		const_iterator findNext( const_iterator &it, const Key &key ) const {
+				return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->findNext( it, key ) );
+		}
 
 		/// Inserts the given key-value pair into the outermost scope
@@ -208,5 +214,10 @@
 		}
 		std::pair< iterator, bool > insert( const Key &key, const Value &value ) { return insert( std::make_pair( key, value ) ); }
-		
+
+		Value& operator[] ( const Key &key ) {
+			iterator slot = find( key );
+			if ( slot != end() ) return slot->second;
+			return insert( key, Value() ).first->second;
+		}
 	};
 } // namespace GenPoly
