Index: src/GenPoly/ScopedMap.h
===================================================================
--- src/GenPoly/ScopedMap.h	(revision 52bbd67b0b24acd72bbc1ae86a63290854312742)
+++ src/GenPoly/ScopedMap.h	(revision 933667da0b0b2c10e059816d1a2fa308a10dcc14)
@@ -176,9 +176,13 @@
 		const_iterator cend() const { return const_iterator(scopes, scopes[0].end(), 0); }
 
+		/// Gets the index of the current scope (counted from 1)
+		size_type currentScope() const { return scopes.size(); }
+
 		/// Finds the given key in the outermost scope it occurs; returns end() for none such
 		iterator find( const Key &key ) {
-			for ( size_type i = scopes.size() - 1; i > 0; --i ) {
+			for ( size_type i = scopes.size() - 1; ; --i ) {
 				typename Scope::iterator val = scopes[i].find( key );
 				if ( val != scopes[i].end() ) return iterator( scopes, val, i );
+				if ( i == 0 ) break;
 			}
 			return end();
@@ -189,7 +193,8 @@
 		iterator findNext( const_iterator &it, const Key &key ) {
 			if ( it.i == 0 ) return end();
-			for ( size_type i = it.i - 1; i > 0; --i ) {
+			for ( size_type i = it.i - 1; ; --i ) {
 				typename Scope::iterator val = scopes[i].find( key );
 				if ( val != scopes[i].end() ) return iterator( scopes, val, i );
+				if ( i == 0 ) break;
 			}
 			return end();
