Index: /cpp/frams/genetics/f4/f4_general.cpp
===================================================================
--- /cpp/frams/genetics/f4/f4_general.cpp	(revision 1227)
+++ /cpp/frams/genetics/f4/f4_general.cpp	(revision 1228)
@@ -33,11 +33,11 @@
 }
 
-int scanrec(const char* s, size_t slen, char stopchar)
-{
-	size_t i = 0;
+int scanRecur(const char* s, int slen, char stopchar)
+{
+	int i = 0;
 	//DB( printf("    scan('%s', '%c')\n", s, stopchar); )
 	while (1)
 	{
-		if (i >= slen)  // ran out the string, should never happen with correct string
+		if (i >= slen)  // ran out the string, should never happen with a correct string
 			return 1;
 		if (stopchar == s[i])  // bumped into stopchar
@@ -47,22 +47,22 @@
 			if (s[i] == '(')
 			{
-				i += 2 + scanrec(s + i + 1, slen - i - 1, ')');
+				i += 2 + scanRecur(s + i + 1, slen - i - 1, ')');
 				continue;
 			}
 			if (s[i] == '<')
 			{
-				i += 2 + scanrec(s + i + 1, slen - i - 1, '>');
+				i += 2 + scanRecur(s + i + 1, slen - i - 1, '>');
 				continue;
 			}
 			if (s[i] == '#')
 			{
-				i += 2 + scanrec(s + i + 1, slen - i - 1, '>');
+				i += 2 + scanRecur(s + i + 1, slen - i - 1, '>');
 				continue;
 			}
 		}
-		// s[i] a non-special character
+		// s[i] is a non-special character
 		i++;
 	}
-	return int(i);
+	return i;
 }
 
@@ -703,5 +703,4 @@
 f4_Cells::f4_Cells(SString & genome, int nrepair)
 {
-	int res;
 	repair = nrepair;
 	errorcode = GENOPER_OK;
@@ -715,6 +714,6 @@
 	// transform geno from string to nodes
 	f4rootnode = new f4_Node();
-	res = f4_processrec(genome.c_str(), 0, f4rootnode);
-	if ((res < 0) || (1 != f4rootnode->childCount()))
+	int res = f4_processRecur(genome.c_str(), 0, f4rootnode);
+	if (res || (f4rootnode->childCount() != 1))
 	{
 		errorcode = GENOPER_OPFAIL;
@@ -833,5 +832,5 @@
 		switch (c->type)
 		{
-		case CELL_UNDIFF: type = "UNDIFF"; break;
+		case CELL_UNDIFF: type = "undiff"; break;
 		case CELL_STICK:  type = "STICK"; break;
 		case CELL_NEURON: type = string("NEURON:") + c->neuclass->name.c_str(); break;
@@ -1218,5 +1217,5 @@
 {
 	int n = count();
-	// pick a random node, between 0 and n-1
+	// pick a random node between 0 and n-1
 	return ordNode(rndUint(n));
 }
@@ -1341,10 +1340,8 @@
 // scan genotype string and build tree
 // return >1 for error (errorpos)
-int f4_processrec(const char* genot, unsigned pos0, f4_Node *parent)
-{
-	int i, res;
-	unsigned gpos, oldpos;
-	f4_Node *node1, *par;
-	unsigned beginindex;
+int f4_processRecur(const char* genot, unsigned pos0, f4_Node *parent)
+{
+	unsigned int gpos;
+	f4_Node *par;
 
 	gpos = pos0;
@@ -1359,19 +1356,19 @@
 		{
 			// find out genotype start for child
-			int j = scanrec(genot + gpos + 1, strlen(genot + gpos + 1), '>');
-
-			node1 = new f4_Node("<", par, gpos);
-			par = node1;
-			res = f4_processrec(genot, gpos + 1, par);
+			int stopchar_offset = scanRecur(genot + gpos + 1, (int)strlen(genot + gpos + 1), '>');
+
+			f4_Node *node = new f4_Node("<", par, gpos);
+			par = node;
+			int res = f4_processRecur(genot, gpos + 1, par);
 			if (res) return res;
-			if (gpos + j + 2 < strlen(genot))
-			{
-				res = f4_processrec(genot, gpos + j + 2, par);
+			if (gpos + stopchar_offset + 2 < strlen(genot))
+			{
+				res = f4_processRecur(genot, gpos + stopchar_offset + 2, par);
 				if (res) return res;
 			}
 			else // ran out
 			{
-				node1 = new f4_Node(">", par, int(strlen(genot)) - 1);
-				par = node1;
+				node = new f4_Node(">", par, int(strlen(genot)) - 1);
+				par = node;
 			}
 			gpos++;
@@ -1380,6 +1377,6 @@
 		case '>':
 		{
-			node1 = new f4_Node(">", par, gpos);
-			par = node1;
+			f4_Node *node = new f4_Node(">", par, gpos);
+			par = node;
 			gpos = (unsigned int)strlen(genot);
 			return 0;  // OK
@@ -1390,26 +1387,25 @@
 			ExtValue val;
 			const char* end = val.parseNumber(genot + gpos + 1, ExtPType::TInt);
-			if (end == NULL) i = 1;
-			else i = val.getInt();
+			int reps = (end == NULL) ? 1 : val.getInt();
 			// find out genotype start for continuation
-			int j = scanrec(genot + gpos + 1, strlen(genot + gpos + 1), '>');
+			int stopchar_offset = scanRecur(genot + gpos + 1, (int)strlen(genot + gpos + 1), '>');
 			// skip number
-			oldpos = gpos;
+			unsigned int oldpos = gpos;
 			gpos += end - (genot + gpos);
 			//gpos++;
 			//while ((genot[gpos] >= '0') && (genot[gpos] <= '9')) gpos++;node1 = new f4_Node("#", par, oldpos);
-			node1 = new f4_Node("#", par, oldpos);
-			node1->reps = i;
-			par = node1;
-			res = f4_processrec(genot, gpos, node1);
+			f4_Node *node = new f4_Node("#", par, oldpos);
+			node->reps = reps;
+			par = node;
+			int res = f4_processRecur(genot, gpos, node);
 			if (res) return res;
-			if (oldpos + j + 2 < strlen(genot))
-			{
-				res = f4_processrec(genot, oldpos + j + 2, node1);
+			if (oldpos + stopchar_offset + 2 < strlen(genot))
+			{
+				res = f4_processRecur(genot, oldpos + stopchar_offset + 2, node);
 				if (res) return res;
 			}
 			else // ran out
 			{
-				node1 = new f4_Node(">", par, int(strlen(genot)) - 1);
+				node = new f4_Node(">", par, int(strlen(genot)) - 1);
 			}
 			return 0;  // OK
@@ -1430,14 +1426,14 @@
 				return gpos + 1; //error
 			gpos += 2; //skipping "N:"
-			beginindex = gpos;
-			char* end = (char*)genot + beginindex;
+			unsigned int begin_index = gpos;
+			char* end = (char*)genot + begin_index;
 			NeuroClass *neuclass = GenoOperators::parseNeuroClass(end, ModelEnum::SHAPETYPE_BALL_AND_STICK);
 			if (neuclass == NULL)
 				return gpos + 1; //error
-			gpos += end - genot - beginindex;
-			string neutype = string(genot + beginindex, genot + gpos);
-			node1 = new f4_Node(neutype, par, forgenorange);
-			node1->neuclass = neuclass;
-			par = node1;
+			gpos += end - genot - begin_index;
+			string neutype = string(genot + begin_index, genot + gpos);
+			f4_Node *node = new f4_Node(neutype, par, forgenorange);
+			node->neuclass = neuclass;
+			par = node;
 			// if it continues with a colon that determines a neuron parameter (e.g. N:N:+=: ), then let the switch case for colon handle this
 			break;
@@ -1459,10 +1455,10 @@
 				return gpos + 1 + 1; //error
 			}
-			node1 = new f4_Node(":", par, gpos);
-			node1->prop_symbol = prop_symbol;
-			node1->prop_increase = prop_dir == '+' ? true : false; // + or -
-			par = node1;
-			int chars = scanrec(genot + gpos + 1, strlen(genot + gpos + 1), ':');
-			gpos += chars + 2;
+			f4_Node *node = new f4_Node(":", par, gpos);
+			node->prop_symbol = prop_symbol;
+			node->prop_increase = prop_dir == '+' ? true : false; // + or -
+			par = node;
+			int stopchar_offset = scanRecur(genot + gpos + 1, (int)strlen(genot + gpos + 1), ':');
+			gpos += stopchar_offset + 2;
 			break;
 		}
@@ -1475,10 +1471,10 @@
 				return gpos + 1; //error
 
-			node1 = new f4_Node("[", par, gpos);
-			node1->conn_from = relfrom;
-			node1->conn_weight = weight;
-			par = node1;
-			int j = scanrec(genot + gpos + 1, strlen(genot + gpos + 1), ']');
-			gpos += j + 2;
+			f4_Node *node = new f4_Node("[", par, gpos);
+			node->conn_from = relfrom;
+			node->conn_weight = weight;
+			par = node;
+			int stopchar_offset = scanRecur(genot + gpos + 1, (int)strlen(genot + gpos + 1), ']');
+			gpos += stopchar_offset + 2;
 			break;
 		}
@@ -1486,6 +1482,6 @@
 		{
 			//printf("any regular character '%c'\n", genot[gpos]);
-			node1 = new f4_Node(genot[gpos], par, gpos);
-			par = node1;
+			f4_Node *node = new f4_Node(genot[gpos], par, gpos);
+			par = node;
 			gpos++;
 			break;
@@ -1499,6 +1495,6 @@
 		if (par->name != ">")
 		{
-			node1 = new f4_Node('>', par, int(strlen(genot)) - 1);
-			par = node1;
+			f4_Node *node = new f4_Node('>', par, int(strlen(genot)) - 1);
+			par = node;
 		}
 	}
@@ -1526,8 +1522,9 @@
 }
 
-f4_Node* f4_processtree(const char* geno)
+/*
+f4_Node* f4_processTree(const char* geno)
 {
 	f4_Node *root = new f4_Node();
-	int res = f4_processrec(geno, 0, root);
+	int res = f4_processRecur(geno, 0, root);
 	if (res) return NULL;
 	//DB( printf("test f4  "); )
@@ -1545,2 +1542,3 @@
 		return root->child;
 }
+*/
Index: /cpp/frams/genetics/f4/f4_general.h
===================================================================
--- /cpp/frams/genetics/f4/f4_general.h	(revision 1227)
+++ /cpp/frams/genetics/f4/f4_general.h	(revision 1228)
@@ -51,5 +51,5 @@
  * @return 1 if end of string was reached, or position of found character in sequence
  */
-int scanrec(const char* s, unsigned int slen, char stopchar);
+int scanRecur(const char* s, int slen, char stopchar);
 
 
@@ -475,9 +475,9 @@
 /**
  * The main function for converting a string of f4 encoding to a tree structure. Prepares
- * f4_Node root of tree and runs f4_processrec function for it.
+ * f4_Node root of tree and runs f4_processRecur function for it.
  * @param geno the string representing an f4 genotype
  * @return a pointer to the f4_Node object representing the f4 tree root
  */
-f4_Node* f4_processtree(const char *geno);
+//f4_Node* f4_processTree(const char *geno);
 
 /**
@@ -485,5 +485,5 @@
  * a tree of f4_Node objects. This method extracts each potentially functional element
  * of a genotype string to a separate f4_Nodes. When the branching character '<' occurs,
- * f4_processrec is deployed for the latest f4_Node element. This method does not
+ * f4_processRecur is deployed for the latest f4_Node element. This method does not
  * analyse the genotype semantically, it only checks if the syntax is proper. The only
  * semantic aspect is neuron class name extraction, where the GenoOperators
@@ -494,5 +494,5 @@
  * @return 0 if processing was successful, otherwise returns the position of an error in the genotype
  */
-int f4_processrec(const char *genot, unsigned pos0, f4_Node *parent);
+int f4_processRecur(const char *genot, unsigned pos0, f4_Node *parent);
 
 /**
Index: /cpp/frams/genetics/f4/f4_oper.cpp
===================================================================
--- /cpp/frams/genetics/f4/f4_oper.cpp	(revision 1227)
+++ /cpp/frams/genetics/f4/f4_oper.cpp	(revision 1228)
@@ -13,7 +13,7 @@
 // TODO getting rid of redundancy (having valid genotypes with a lot of "junk code") in this representation looks like a good idea.
 // 
-// Note: symbols after the last > are ignored, for example /*4*/<X>N:N>N:N[2:-0.5]XXXwhatever but since they are not parsed into the f4_Node tree, they will be lost after any mutation.
+// Note: symbols after the last > are ignored, for example /*4*/<X>N:N>blablaN:N[2:-0.5]XXXwhatever but since they are not parsed into the f4_Node tree, they will be lost after any mutation.
 //
-// TODO the behavior of neuron input indexes during mutation seems badly implemented (see also TREAT_BAD_CONNECTIONS_AS_ERRORS). Are they kept properly maintained when nodes are added and removed? This could be done well because during mutation we operate on the tree structure with cross-references between nodes (so they should not be affected by local changes in the tree), and then convert the tree back to string. Yet, the f4_Node.conn_from is an integer and these fields in nodes do not seem to be maintained on tree node adding/removal... change these integer offsets to references to node objects? But actually, do the offsets that constitute relative connection references concern the f4_Node tree structure (and all these sophisticated calculations of offsets during mutation are useful) or rather they concern the f4_Cells development? verify all situations in f4_Cell::oneStep(), case '['.
+// TODO the behavior of neuron input indexes during mutation seems badly implemented (see also TREAT_BAD_CONNECTIONS_AS_INVALID_GENO). Are they kept properly maintained when nodes are added and removed? This could be done well because during mutation we operate on the tree structure with cross-references between nodes (so they should not be affected by local changes in the tree), and then convert the tree back to string. Yet, the f4_Node.conn_from is an integer and these fields in nodes do not seem to be maintained on tree node adding/removal... change these integer offsets to references to node objects? But actually, do the offsets that constitute relative connection references concern the f4_Node tree structure (and all these sophisticated calculations of offsets during mutation are useful) or rather they concern the f4_Cells development? verify all situations in f4_Cell::oneStep(), case '['.
 // TODO add simplifying sequences of modifiers (so capital and small letter cancel out, like in f1) - but seems like each single modifier is a separate f4_Node? and perhaps we don't want to use the repair mechanism for this... maybe mutations, when they add/modify/remove a modifier node, should be "cleaning" the tree by removing nodes when they encounter contradictory modifiers on the same subpath?
 // TODO add support for properties of (any class of) neurons - not just sigmoid/force/intertia (':' syntax) for N
@@ -122,5 +122,5 @@
 	// convert geno to tree, then try to validate 20 times
 	f4_Node root;
-	if (f4_processrec(geno, 0, &root) || root.childCount() != 1) return GENOPER_OK; // cannot repair
+	if (f4_processRecur(geno, 0, &root) || root.childCount() != 1) return GENOPER_OK; // cannot repair
 	if (ValidateRec(&root, 20) == GENOPER_REPAIR) // if repaired, make it back to string
 	{
@@ -135,5 +135,5 @@
 {
 	f4_Node root;
-	int res = f4_processrec(geno, 0, &root);
+	int res = f4_processRecur(geno, 0, &root);
 	if (res) return res;  // errorpos, >0
 	if (root.childCount() != 1) return 1; //earlier: GENOPER_OPFAIL
@@ -208,5 +208,5 @@
 							// The "false" argument in findConnectionNeuronIndexes() below is not suffient, because we also need to access (find) the f4_Node of the other neuron.
 							// A similar logic is implemented in F4_ADD_CONN below, but let's not complicate this F4_ADD_DIV mutation anymore.
-							// A disadvantage is that the node_new_neuron added here which is a neuron that provides output (e.g., a receptor, N, etc.) will not get connected immediately here even when there are already existing neurons wanting inputs (e.g., muscles, N, etc.).
+							// The disadvantage is that the node_new_neuron added here which is a neuron that provides output (e.g., a receptor, N, etc.) will not get connected immediately here even when there are already existing neurons wanting inputs (e.g., muscles, N, etc.).
 							//bool ok = findConnectionNeuronIndexes(g, ... , false, ..., ...);
 						}
@@ -230,5 +230,5 @@
 
 			// the probability that a randomly selected node will be a neuron and additionally this neuron will accept inputs is low,
-			// so we disregard randomly picked node_mutated and build a list of all valid candidate nodes here, then select a random one from them.
+			// so we disregard randomly picked node_mutated and build a list of all valid candidate nodes here, then randomly select one from them.
 
 			vector<f4_Node*> candidate_nodes; //neurons that accept input(s)
@@ -476,5 +476,5 @@
 	// relative input connection to some existing neuron
 	nn->conn_from = nn_index - other_index;
-	//nn->conn_from = (int)(4.0f * (rndDouble(1) - 0.5f)); //in very old times - did not care about neuron input/output preferences
+	//nn->conn_from = (int)(4.0f * (rndDouble(1) - 0.5)); //in very old times - did not care about neuron input/output preferences
 
 	nn->conn_weight = GenoOperators::getMutatedNeuronConnectionWeight(nn->conn_weight);
@@ -493,5 +493,5 @@
 void Geno_f4::repeatNodeChangeRandom(f4_Node *nn) const
 {
-	if (rndDouble(1) < 0.5f) nn->reps++; else nn->reps--; // change count
+	if (rndDouble(1) < 0.5) nn->reps++; else nn->reps--; // change count
 	if (nn->reps < 1) nn->reps = 1;
 	if (nn->reps > mut_max_rep) nn->reps = mut_max_rep;
@@ -547,5 +547,5 @@
 {
 	f4_Node *root = new f4_Node;
-	if (f4_processrec(g, 0, root) || root->childCount() != 1)
+	if (f4_processRecur(g, 0, root) || root->childCount() != 1)
 	{
 		delete root;
@@ -607,5 +607,5 @@
 
 // decide number of nodes to mutate
-n = (int)( 0.5f + rndDouble(1) * maxToMut );
+n = (int)( 0.5 + rndDouble(1) * maxToMut );
 if (n<1) n=1;
 if (n>totNodes) n=totNodes;
@@ -671,6 +671,6 @@
 
 	// convert genotype strings into tree structures
-	if (f4_processrec(g1, 0, &root1) || (root1.childCount() != 1)) return GENOPER_OPFAIL;
-	if (f4_processrec(g2, 0, &root2) || (root2.childCount() != 1)) return GENOPER_OPFAIL;
+	if (f4_processRecur(g1, 0, &root1) || (root1.childCount() != 1)) return GENOPER_OPFAIL;
+	if (f4_processRecur(g2, 0, &root2) || (root2.childCount() != 1)) return GENOPER_OPFAIL;
 
 	// decide amounts of crossover, 0.25-0.75
