diff --git a/src/ac/ed/lurg/utils/cluster/Cluster.java b/src/ac/ed/lurg/utils/cluster/Cluster.java
index d96f36409648942bd9b48409334db8e2a6cf67f6..1ad395fb9d24e00d7c0d599fa1d67a1001307128 100644
--- a/src/ac/ed/lurg/utils/cluster/Cluster.java
+++ b/src/ac/ed/lurg/utils/cluster/Cluster.java
@@ -55,7 +55,9 @@ public class Cluster<K, P extends ClusteringPoint<K>> {
     protected double distanceFromCentroid(ClusteringPoint<K> p) {
     	double squaredTotal=0;
     	for (K key : centroid.getAllClusteringKeys()) {
-       		squaredTotal += Math.pow(centroid.getClusteringValue(key)-p.getClusteringValue(key), 2);
+    		double a = centroid.getClusteringValue(key);
+    		double b = p.getClusteringValue(key);
+    		squaredTotal += Math.pow(a-b, 2);
     	}
     	
         return Math.sqrt(squaredTotal);
diff --git a/src/ac/ed/lurg/yield/YieldClusterPoint.java b/src/ac/ed/lurg/yield/YieldClusterPoint.java
index 91f9eb806ce9ddf2cc0013026b19b985a130f115..7b3882eb2f70f7e23173bd9d18872f6ab639eeff 100644
--- a/src/ac/ed/lurg/yield/YieldClusterPoint.java
+++ b/src/ac/ed/lurg/yield/YieldClusterPoint.java
@@ -51,7 +51,11 @@ public class YieldClusterPoint implements ClusteringPoint<String> {
 
 	@Override
 	public double getClusteringValue(String key) {
-
+		double v = getClusteringValueNaN(key);		
+		return Double.isNaN(v) ? 0.0 : v;  // LPJ with emulator provides NaN yields.  How to cluster these is tricky, but assuming they are 0 
+	}
+	
+	private double getClusteringValueNaN(String key) {
 		switch (key) {
 			case PASTURE:  return pasture;
 			case WHEAT_MIN:  return wheatMin;
@@ -61,9 +65,9 @@ public class YieldClusterPoint implements ClusteringPoint<String> {
 			case MAIZE_MAX:  return maizeMax;
 			case IRRIG_WATER_AVAL:  return irrigWaterAval;
 			case PROTECTED_AREA:  return protectedArea;
+			default:
+				throw new RuntimeException("YieldClusterPoint.getClusteringValue: got unknown value " + key);
 		}
-		LogWriter.printlnError("YieldClusterPoint.getClusteringValue: got unknown value " + key);
-		return Double.NaN;
 	}
 
 	@Override