 					var i4:Number= i3 -1;
 					if(i4 !=0)
 					{
-						for (var p:Number = 2; p < numOfBins.value + 1; p++)
+						_p = 2;
+						for (; _p < numOfBins.value + 1; _p++)
 						{
-							if((_mat2[_count][p]) >= (_v + _mat2[i4][p-1]))
+							
+							if((_mat2[_count][_p]) >= (_v + _mat2[i4][_p-1]))
 							{
-								_mat1[_count][p] = i3;
-								_mat2[_count][p] = _v +_mat2[i4][p-1];
+								_mat1[_count][_p] = i3;
+								_mat2[_count][_p] = _v +_mat2[i4][_p-1];
 							}
 						}
 					}
 				}
+				_m = 0;
 				_mat1[_count][1] = 1;
 				_mat2[_count][1] = _v;
 			}

	import mx.utils.ObjectUtil;
	
	import weave.api.WeaveAPI;
	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)

		
		private var _output:ILinkableHashMap = null;
		private var _column:IAttributeColumn = null;
		private var asyncSort:AsyncSort = new AsyncSort();
		override public function generateBinClassifiersForColumn(column:IAttributeColumn):void
		{
			_output = output;
