Index: /other-projects/maori-lang-detection/src/org/greenstone/atea/CountryCodeCountsMapData.java
===================================================================
--- /other-projects/maori-lang-detection/src/org/greenstone/atea/CountryCodeCountsMapData.java	(revision 33857)
+++ /other-projects/maori-lang-detection/src/org/greenstone/atea/CountryCodeCountsMapData.java	(revision 33858)
@@ -347,5 +347,5 @@
 	// to grow northwards.
 	Double north = lat + (vertical_factor * count);
-	
+	    
 	while (north > 90) {
 	    // recalculate north after decreasing histogram's vertical growth
@@ -358,27 +358,45 @@
 	Double west = lng - half_width;
 	Double south = lat;
-	    
+	/*
+	System.err.println("For country " + countryCode + ":");
+	System.err.println("north = " + north);
+	System.err.println("south = " + south);
+	System.err.println("east = " + east);
+	System.err.println("west = " + west + "\n");
+	*/
 	// Check if we're dealing with very large numbers, in which case, we can have follow off the longitude edges
-	// Max longitude values are -180 to 180. So a max of 360 units between them.
+	// Max longitude values are -180 to 180. So a max of 360 units between them. (Max latitude is -90 to 90)
+	// "Longitude is in the range -180 and +180 specifying coordinates west and east of the Prime Meridian, respectively.
+	// For reference, the Equator has a latitude of 0Â°, the North pole has a latitude of 90Â° north (written 90Â° N or +90Â°),
+	// and the South pole has a latitude of -90Â°."
 	if((east + Math.abs(west)) > 360 || east > 180 || west < -180) {
 	    half_width = HISTOGRAM_WIDTH/2; // reset half_width
 	    
 	    double v_tmp_count = Math.sqrt(count);
-	    double h_tmp_count = Math.floor(v_tmp_count);
-	    v_tmp_count = Math.ceil(v_tmp_count);
+	    //double h_tmp_count = Math.floor(v_tmp_count);
+	    //v_tmp_count = Math.ceil(v_tmp_count);
+	    double h_tmp_count = v_tmp_count;
 
 	    /*
-	    System.err.println("HERE, count = " + count);
-	    System.err.println("HERE, v = " + v_tmp_count);
-	    System.err.println("HERE, h = " + h_tmp_count);
-	    System.err.println("HERE, lat = " + lat);
-	    System.err.println("HERE, lng = " + lng + "\n");
+	    System.err.println("Recalculating polygon for country with high count: " + countryCode + ".");
+	    System.err.println("count = " + count);
+	    System.err.println("v = " + v_tmp_count);
+	    System.err.println("h = " + h_tmp_count);
+	    System.err.println("lat = " + lat);
+	    System.err.println("lng = " + lng + "\n");	    
 	    */
-
+	    
 	    north = lat + v_tmp_count;
 	    south = lat;
-	    east = lng + (h_tmp_count/2 * half_width); // a certain width, half_width, represents one unit in the x axis
-	    west = lng - (h_tmp_count/2 * half_width);
-
+	    east = lng + (h_tmp_count * half_width); // a certain width, half_width, represents one unit in the x axis
+	    west = lng - (h_tmp_count * half_width);
+
+	    /*
+	System.err.println("north = " + north);
+	System.err.println("south = " + south);
+	System.err.println("east = " + east);
+	System.err.println("west = " + west + "\n");
+	    */
+	    
 	    if(north > 90) {
 		// centre vertically on lat
@@ -388,25 +406,17 @@
 
 	    if(west < -180.0) {
-		double h_diff = lng - 180.0; // the country's longitude (lng) is h_diff from the western edge
-		west = 180.0; // maximise western edge
-		east = h_tmp_count - h_diff/half_width;// then grow the remainder of h_tmp_count in the opposite (eastern) direction
+		double h_diff = -180.0 - west; // west is a larger negative value than -180, so subtracting west from -180 produces a positive h_diff value
+		west = -180.0; // set to extreme western edge
+		east = east + h_diff;
 	    }	    
 	    else if(east > 180.0) {
-		double h_diff = 180.0 - lng; // the country's longitude (lng) is h_diff from the eastern edge
+		double h_diff = east - 180.0; // the country's longitude (lng) is h_diff from the eastern edge
 		east = 180.0; // maximise eastern edge
-		west = -1 * (h_tmp_count - (h_diff/half_width)); // then grow the remainder of h_tmp_count in the opposite (western) direction
+		west = west - h_diff; // then grow the remainder of h_tmp_count in the opposite (western/negative) direction
 	    }
 	    
-	    // CAN'T centre on country, (lat,lng), as we don't know whether either of lat or lng has gone past the edge
-	    //north = lat + (v_tmp_count/2);
-	    //south = lat - (v_tmp_count/2);
-	    //east = lng + (h_tmp_count/2);
-	    //west = lng - (h_tmp_count/2);
-	    
-	    // hopefully we don't exceed +90/-90 lat and +/-180 longitude
-	    // "Longitude is in the range -180 and +180 specifying coordinates west and east of the Prime Meridian, respectively.
-	    // For reference, the Equator has a latitude of 0Â°, the North pole has a latitude of 90Â° north (written 90Â° N or +90Â°),
-	    // and the South pole has a latitude of -90Â°."
-
+	    // NOTE: Can't centre on country, (lat,lng), as we don't know whether either of lat or lng has gone past the edge
+	    
+	    // Hopefully we don't exceed +90/-90 lat and +/-180 longitude
 	    /*
 	    System.err.println("north = " + north);
