         {
 			// Check what locales are not already loaded
             // and push them preserving the order.
-			for (j = 0, k = locales.length; j < k; j++)
+			for (j = 0; j < noLocales; j++)
             {
 				promote(locales[j]);
 			}

		
		var i:int;
        var j:int;
        var k:int;
        var l:int;
		var locale:String;
		
		var locales:Array = trimAndNormalize(appLocales);
		var preferenceLocales:Array	= trimAndNormalize(systemPreferences);
		
		addUltimateFallbackLocale(preferenceLocales, ultimateFallbackLocale);
		
		// For better performance, save the locales in a lookup table.
		for (j = 0; j < locales.length; j++)
        {
			hasLocale[locales[j]] = j;
		}

			}
		}
		
		var preferenceLocalesID:Vector.<LocaleID> = new Vector.<LocaleID>(noPreferenceLocales);
		for (i = 0; i < noPreferenceLocales; i++)
        {
        	preferenceLocalesID[i] = LocaleID.fromString(preferenceLocales[i]);
        }
		
		var localesID:Vector.<LocaleID> = new Vector.<LocaleID>(noLocales);
		for (i = 0; i < noLocales; i++)
        {
        	localesID[i] = LocaleID.fromString(locales[i]);
        }
		
		for (i = 0; i < noPreferenceLocales; i++)
        {
			var plocale:LocaleID = preferenceLocalesID[i].clone();
			
			// Step 1: Promote the perfect match.
			promote(preferenceLocales[i]);
