 					{
 						return _count/(_sortedValues.length+1);
 					}
-					var i3:Number = _count - _m +1;
-					var val:Number = _sortedValues[i3-1];
+					// `III` originally
+					var lower_class_limit:Number = _count - _m +1;
+					var val:Number = _sortedValues[lower_class_limit-1];
 					
-					_s2 += val * val;
-					_s1 += val;
+					_sum_squares += val * val;
+					_sum += val;
 					
+					// here we're estimating variance for each potential classing
+					// of the data, for each potential number of classes. `w`
+					// is the number of data points considered so far.
 					_w += 1;
-					_v = _s2 - (_s1 * _s1) / _w;
-					var i4:Number= i3 -1;
+					
+					// the variance at this point in the sequence is the difference
+					// between the sum of squares and the total x 2, over the number
+					// of samples.					
+					_variance = _sum_squares - (_sum * _sum) / _w;
+					
+					var i4:Number= lower_class_limit -1;
 					if(i4 !=0)
 					{
 						_p = 2;
 						for (; _p < numOfBins.value + 1; _p++)
 						{
-							
-							if((_mat2[_count][_p]) >= (_v + _mat2[i4][_p-1]))
+							// if adding this element to an existing class
+							// will increase its variance beyond the limit, break
+							// the class at this point, setting the lower_class_limit
+							// at this point.
+							if((_variance_combinations[_count][_p]) >= (_variance + _variance_combinations[i4][_p-1]))
 							{
-								_mat1[_count][_p] = i3;
-								_mat2[_count][_p] = _v +_mat2[i4][_p-1];
+								_lower_class_limits[_count][_p] = lower_class_limit;
+								_variance_combinations[_count][_p] = _variance +_variance_combinations[i4][_p-1];
 							}
 						}
 					}
 				}
 				_m = 0;
-				_mat1[_count][1] = 1;
-				_mat2[_count][1] = _v;
+				_lower_class_limits[_count][1] = 1;
+				_variance_combinations[_count][1] = _variance;
 			}
 			return 1;
 		}

			
			VectorUtils.copy(_sortedValues,_previousSortedValues);
			
			_mat1 = [];
			_mat2 = [];
			for (var i:int = 0; i < _sortedValues.length+1; i++)
			{
				var temp1:Array = [];
				var temp2:Array = [];
				
				for(var j:int =0; j < numOfBins.value+1; j++)
				{
					temp1.push(0);
					temp2.push(0);
				}
				_mat1.push(temp1);
				_mat2.push(temp2);
			}
			
			for (var k:int =1; k < numOfBins.value + 1; k++)
			{
				_mat1[0][k] = 1;
				_mat2[0][k] = 0;
				
				for (var t:int =1; t<_sortedValues.length+1; t++)
				{
					_mat2[t][k] = Number.POSITIVE_INFINITY;
				}
			}
			
			_v = 0;
			_count = 2;
			_m = 0;
			

	import weave.utils.VectorUtils;
	
	/**
	 * Implemented from https://gist.github.com/tmcw/4977508
	 * Also, read : http://macwright.org/2013/02/18/literate-jenks.html
	 * Other implementations from Doug Curl (javascript) and Daniel J Lewis (python implementation) and  Simon Georget (Geostats)
	 * http://www.arcgis.com/home/item.html?id=0b633ff2f40d412995b8be377211c47b
	 * http://danieljlewis.org/2010/06/07/jenks-natural-breaks-algorithm-in-python/
	 * https://github.com/simogeo/geostats/blob/master/lib/geostats.js
