Index: /cpp/frams/genetics/fF/conv_fF.cpp
===================================================================
--- /cpp/frams/genetics/fF/conv_fF.cpp	(revision 177)
+++ /cpp/frams/genetics/fF/conv_fF.cpp	(revision 178)
@@ -16,5 +16,5 @@
 	cosines = new double[fF_LATITUDE_NUM];
 	sines = new double[fF_LATITUDE_NUM];
-	fill_cos_and_sin();
+	precompute_cos_and_sin();
 }
 
@@ -159,11 +159,11 @@
 		pun = find_hole(which, pzx, pzy, pzz, chambers, kx_, ky_, kz_);
 
-		chambers[which]->holeX = (float)chambers[which]->points[pun][0];
-		chambers[which]->holeY = (float)chambers[which]->points[pun][1];
-		chambers[which]->holeZ = (float)chambers[which]->points[pun][2];
-	}
-}
-
-void GenoConv_fF0::fill_cos_and_sin()
+		chambers[which]->holeX = (float)chambers[which]->points[pun].x;
+		chambers[which]->holeY = (float)chambers[which]->points[pun].y;
+		chambers[which]->holeZ = (float)chambers[which]->points[pun].z;
+	}
+}
+
+void GenoConv_fF0::precompute_cos_and_sin()
 {
 	int i;
@@ -177,5 +177,5 @@
 }
 
-double** GenoConv_fF0::generate_points(fF_chamber3d *chamber, int which, double kx_, double ky_, double kz_)
+fF_point* GenoConv_fF0::generate_points(fF_chamber3d *chamber, int which, double kx_, double ky_, double kz_)
 {
 	float radius = chamber->radius;
@@ -210,9 +210,5 @@
 	double rz = all_k_ones ? radius : kz;
 
-	double **points = new double*[fF_SIZE];
-	for (int i = 0; i < fF_SIZE; i++)
-	{
-		points[i] = new double[4];
-	}
+	fF_point *points = new fF_point[fF_SIZE];
 
 	for (int i = 0; i < fF_LONGITUDE_NUM; i++)
@@ -224,9 +220,9 @@
 			double x = cenx + rx * cosines[j] * sines[i];
 			double z = cenz + rz * sines[j] * sines[i];
-			double *p = points[(i * fF_LATITUDE_NUM) + j];
-			p[0] = x;
-			p[1] = y;
-			p[2] = z;
-			p[3] = 1.0;
+			fF_point &p = points[(i * fF_LATITUDE_NUM) + j];
+			p.x = x;
+			p.y = y;
+			p.z = z;
+			p.inside = false;
 
 			if (x < minX) minX = x;
@@ -267,12 +263,9 @@
 		for (int j = 0; j < fF_AMOUNT; j++)
 		{
-			double *p = spheres[nr]->points[j];
-			double X = p[0];
-			double Y = p[1];
-			double Z = p[2];
-
-			double up1 = (X - srX0) * (X - srX0);
-			double up2 = (Y - srY0) * (Y - srY0);
-			double up3 = (Z - srZ0) * (Z - srZ0);
+			fF_point &p = spheres[nr]->points[j];
+
+			double up1 = (p.x - srX0) * (p.x - srX0);
+			double up2 = (p.y - srY0) * (p.y - srY0);
+			double up3 = (p.z - srZ0) * (p.z - srZ0);
 
 			double exp1 = up1 / a2;
@@ -284,5 +277,5 @@
 			if (result < fF_THICK_RATIO)
 			{
-				p[3] = 0.0;
+				p.inside = true;
 			}
 		}
@@ -301,8 +294,8 @@
 	for (int i = 0; i < fF_AMOUNT; i++)
 	{
-		double *p = chambers[which]->points[i];
-		if (p[3] != 0) //it is not inside another chamber
-		{
-			double distancesq = (p[0] - x)*(p[0] - x) + (p[1] - y)*(p[1] - y) + (p[2] - z)*(p[2] - z);
+		fF_point &p = chambers[which]->points[i];
+		if (!p.inside) //it is not inside another chamber
+		{
+			double distancesq = (p.x - x)*(p.x - x) + (p.y - y)*(p.y - y) + (p.z - z)*(p.z - z);
 			if (found < 0)
 			{
@@ -314,7 +307,4 @@
 				if (which != 0)
 				{
-					double X = p[0];
-					double Y = p[1];
-					double Z = p[2];
 					bool good = true;
 					for (int j = 0; j < which && good; j++)
@@ -330,7 +320,7 @@
 						double c2 = kzsq * radsq;
 
-						double up1 = (X - srX0) * (X - srX0);
-						double up2 = (Y - srY0) * (Y - srY0);
-						double up3 = (Z - srZ0) * (Z - srZ0);
+						double up1 = (p.x - srX0) * (p.x - srX0);
+						double up2 = (p.y - srY0) * (p.y - srY0);
+						double up3 = (p.z - srZ0) * (p.z - srZ0);
 
 						double exp1 = up1 / a2;
Index: /cpp/frams/genetics/fF/conv_fF.h
===================================================================
--- /cpp/frams/genetics/fF/conv_fF.h	(revision 177)
+++ /cpp/frams/genetics/fF/conv_fF.h	(revision 178)
@@ -24,4 +24,13 @@
 #include "fF_chamber3d.h"
 
+
+//A point on the surface of a chamber
+struct fF_point
+{
+	double x, y, z;
+	bool inside; //helper field used when computing whether this point is inside some chamber
+};
+
+
 // The f9->f0 converter
 class GenoConv_fF0 : public GenoConverter {
@@ -33,13 +42,15 @@
 
 protected:
-	double* cosines;
-	double* sines;
 	void createSphere(int ktora, fF_chamber3d **chambers, double radius, double div_radius_length, double div_vector_length,
 		double alpha, double gamma, double kx, double ky, double kz);
-	double** generate_points(fF_chamber3d *chamber, int which, double kx, double ky, double kz);
-	void fill_cos_and_sin();
+	fF_point* generate_points(fF_chamber3d *chamber, int which, double kx, double ky, double kz);
 	double dist(double x1, double y1, double z1, double x2, double y2, double z2);
 	void search_hid(int nr, fF_chamber3d **spheres, double kx_, double ky_, double kz_);
 	int find_hole(int which, double x, double y, double z, fF_chamber3d **chambers, double kx_, double ky_, double kz_);
+
+private:
+	double* cosines;
+	double* sines;
+	void precompute_cos_and_sin();
 };
 
Index: /cpp/frams/genetics/fF/fF_chamber3d.cpp
===================================================================
--- /cpp/frams/genetics/fF/fF_chamber3d.cpp	(revision 177)
+++ /cpp/frams/genetics/fF/fF_chamber3d.cpp	(revision 178)
@@ -9,6 +9,4 @@
 fF_chamber3d::~fF_chamber3d()
 {
-	for (int i = 0; i < fF_SIZE; i++)
-		delete[] points[i];
 	delete[] points;
 }
Index: /cpp/frams/genetics/fF/fF_chamber3d.h
===================================================================
--- /cpp/frams/genetics/fF/fF_chamber3d.h	(revision 177)
+++ /cpp/frams/genetics/fF/fF_chamber3d.h	(revision 178)
@@ -5,4 +5,6 @@
 #ifndef CHAMBER3D_H
 #define	CHAMBER3D_H
+
+struct fF_point;
 
 //Chamber parameters; see http://www.framsticks.com/foraminifera
@@ -22,5 +24,5 @@
 	float beta;
 	float phi;
-	double **points;
+	fF_point *points;
 
 	~fF_chamber3d();
