 		// reusable temporary object
 		private static const _tempNumberClassifier:NumberClassifier = new NumberClassifier();
 		
-		
+		private var _output:ILinkableHashMap = null;
+		private var _column:IAttributeColumn = null;
 		override public function getBinClassifiersForColumn(column:IAttributeColumn, output:ILinkableHashMap):void
 		{
-			var name:String;
+			_output = output;
+			_column = column;
 			// clear any existing bin classifiers
-			output.removeAllObjects();
-			
-			var breaks:Array = getJenksBreak(column);
-			
-			var binMin:Number;
-			var binMax:Number; 
-			
-			
-			for (var iBin:int = 0; iBin < numOfBins.value; iBin++)
-			{
-				var minIndex:Number;
-				if(iBin == 0)
-				{
-					minIndex = 0;
-				}
-				else
-				{
-					minIndex = _previousSortedValues.lastIndexOf(_previousBreaks[iBin]);
-					minIndex = minIndex +1;
-				}
-				
-				_tempNumberClassifier.min.value = _previousSortedValues[minIndex];
-				
-				var maxIndex:Number;
-				if(iBin == numOfBins.value -1)
-				{
-					maxIndex = _previousSortedValues.length -1;
-				}
-				else
-				{
-					/* Get the index of the next break */
-					maxIndex = _previousSortedValues.lastIndexOf(_previousBreaks[iBin+1]);
-				}
-				_tempNumberClassifier.max.value = _previousSortedValues[maxIndex];
-				_tempNumberClassifier.minInclusive.value = true;
-				_tempNumberClassifier.maxInclusive.value = true;
-				
-				//first get name from overrideBinNames
-				name = getOverrideNames()[iBin];
-				//if it is empty string set it from generateBinLabel
-				if(!name)
-					name = _tempNumberClassifier.generateBinLabel(column as IPrimitiveColumn);
-				output.requestObjectCopy(name, _tempNumberClassifier);
-			}
-				
-		}
-		
-		/* This function returns the Good Fit Value for the breaks. Not used but just in case*/
-		private function getGVF(column:IAttributeColumn):Number
-		{
-			var listMean:Number = getSumOfNumbers(_previousSortedValues);
-			
-			var SDAM:Number = 0;
-			var sqDev:Number = 0;
-			
-			for(var i:int =0; i < _previousSortedValues.length; i++)
-			{
-				sqDev = Math.pow((_previousSortedValues[i]- listMean), 2);
-				SDAM += sqDev;
-			}
-			
-			
-			var SDCM:Number = 0;
-			var preSDCM:Number;
-			var classStart:Number;
-			var classEnd:Number;
-			var classValues:Array;
-			var classMean:Number;
-			var sqDev2:Number;
-			
-			for(var j:int =0; j < numOfBins.value; j++)
-			{
-				if(_previousBreaks[j] ==0)
-				{
-					classStart = 0;
-				}
-				else
-				{
-					classStart = _previousSortedValues.indexOf(_previousBreaks[j]);
-					classStart += 1;
-				}
-				
-				classEnd = _previousSortedValues.indexOf(_previousBreaks[j+1]);
-				
-				classValues = _previousSortedValues.slice(classStart,classEnd);
-				
-				classMean = getSumOfNumbers(classValues)/classValues.length;
-				
-				for(var k:int =0; k < classValues.length; k++)
-				{
-					sqDev2 = Math.pow((classValues[k] - classMean),2);
-					preSDCM += sqDev2;
-				}
-				
-				SDCM += preSDCM;
-			}
-			
-			return (SDAM - SDCM)/SDAM;
-			
-		}
-		
-		private var _previousSortedValues:Array = [];
-		private var _previousBreaks:Array = [];
-		
-		private function getJenksBreak(column:IAttributeColumn):Array
-		{	
-			_previousBreaks.length = 0;
+			_output.removeAllObjects();
+			
 			_previousSortedValues.length = 0;
 			
-			var sortedValues:Array = getSortedNumbersFromColumn(column);
-			
-			VectorUtils.copy(sortedValues,_previousSortedValues);
-			
-			var mat1:Array = [];
-			var mat2:Array = [];
-			for (var i:int = 0; i < sortedValues.length+1; i++)
+			_sortedValues = getSortedNumbersFromColumn(_column);
+			
+			VectorUtils.copy(_sortedValues,_previousSortedValues);
+			
+			_mat1 = [];
+			_mat2 = [];
+			for (var i:int = 0; i < _sortedValues.length+1; i++)
 			{
 				var temp1:Array = [];
 				var temp2:Array = [];


package weave.data.BinningDefinitions
{
	import mx.utils.ObjectUtil;
	
	import weave.api.registerLinkableChild;
	import weave.api.reportError;
	import weave.api.core.ILinkableHashMap;
	import weave.api.data.IAttributeColumn;
	import weave.api.data.IPrimitiveColumn;
	import weave.api.data.IQualifiedKey;
	import weave.core.LinkableNumber;
	import weave.data.BinClassifiers.NumberClassifier;
	import weave.utils.AsyncSort;
	import weave.utils.VectorUtils;
	
	/**
	 * Implemented from Doug Curl (javascript) and Daniel J Lewis (python implementation) and  Simon Georget (Geostats)

					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;
			
			WeaveAPI.StageUtils.startTask(this,_iterateJenksBreaks,WeaveAPI.TASK_PRIORITY_PARSING,_handleJenksBreaks);
			
		}
		
		private var _previousSortedValues:Array = [];
		private var _sortedValues:Array = [];
		private var _mat1:Array = [];
		private var _mat2:Array = [];
		private var _count:int = 2;
		private var _m:int = 1;
		private var _v:Number = 0;
		private var _s1:Number = 0;
		private var _s2:Number = 0;
		
		private var _w:Number = 0;
		private function _iterateJenksBreaks(returnTime:int):Number
		{
			for (; _count < _sortedValues.length + 1; _count++)
			{
				_s1= 0;
				_s2= 0;
				_w= 0;
				_m =1;			
				
				for(; _m < _count + 1; _m++)
				{
					if(getTimer()>returnTime)
					{
						return 0;
					}
					var i3:Number = _count - _m +1;
					var val:Number = _sortedValues[i3-1];
					
					_s2 += val * val;
					_s1 += val;
					
					_w += 1;
					_v = _s2 - (_s1 * _s1) / _w;
					var i4:Number= i3 -1;
					if(i4 !=0)
					{
						for (var p:Number = 2; p < numOfBins.value + 1; p++)
						{
							if((_mat2[_count][p]) >= (_v + _mat2[i4][p-1]))
							{
								_mat1[_count][p] = i3;
								_mat2[_count][p] = _v +_mat2[i4][p-1];
							}
						}
					}
				}
				_mat1[_count][1] = 1;
				_mat2[_count][1] = _v;
			}
			return 1;
		}
		
		private function _handleJenksBreaks():void
		{
			var kClassCount:Number =  _sortedValues.length;
			var kClass:Array = [];
			
			for(var i:int = 0; i < numOfBins.value +1; i++)
			{
				kClass.push(0);
			}
			
			//this is the last number in the array
			kClass[numOfBins.value] = _sortedValues[_sortedValues.length -1];
			
			//this is the first numer in the array 
			kClass[0] = _sortedValues[0];
			
			
			var countNum:Number = numOfBins.value;
			
			while (countNum >=2)
			{
				var id:Number = _mat1[kClassCount][countNum] -2;
				kClass[countNum -1] = _sortedValues[id];
				kClassCount = _mat1[kClassCount][countNum] -1;
				// spits out the rank and value of the break values:
				// console.log("id="+id,"rank = " + String(mat1[k][countNum]),"val =
				// " + String(dataList[id]))
