 
 					# this might not be necessary if only
 					# the starting node can have a single neighbour
-					if cycledNodes.has node
-						"""
-							while (runtime.isAlive()) _#{node}: {
-								#{edgeCode}
-							}
-						"""
-					else
-						edgeCode
+					wrapIfLooping cycledNodes, node, edgeCode
+
 				when 0
 					'return;'
 

						}
					"""

					if cycledNodes.has node
						"""
							while (runtime.isAlive()) _#{node}: {
								#{randomCode}
							}
						"""
					else
						randomCode
				when 2
					branch0 = df neighbours[0].to, newStack
					branch1 = df neighbours[1].to, newStack

						}
					"""

					wrapIfLooping cycledNodes, node, selectCode

				when 1
					branch = df neighbours[0].to, newStack

