Index: /mds-and-trees/tree-genealogy.py
===================================================================
--- /mds-and-trees/tree-genealogy.py	(revision 710)
+++ /mds-and-trees/tree-genealogy.py	(revision 711)
@@ -727,8 +727,46 @@
             return creature
 
+        def load_creature_props(creature):
+            creature_id = get_id(creature["ID"])
+            for prop in creature:
+                if prop not in default_props:
+                    if prop not in self.props:
+                        self.props[prop] = [0 for i in range(nodes)]
+                    self.props[prop][creature_id] = creature[prop]
+
+        def load_born_props(creature):
+            nonlocal max_time
+            creature_id = get_id(creature["ID"])
+            if "Time" in creature:
+                self.time[creature_id] = creature["Time"] + time_offset
+                max_time = max(self.time[creature_id], max_time)
+
+        def load_offspring_props(creature):
+            creature_id = get_id(creature["ID"])#, False)
+            if "FromIDs" in creature:
+                # make sure that ID's of parents are lower than that of their children
+                for i in range(0, len(creature["FromIDs"])):
+                    if creature["FromIDs"][i] not in self.ids:
+                        get_id("virtual_parent")
+
+
+                # we assign to each parent its contribution to the genotype of the child
+                for i in range(0, len(creature["FromIDs"])):
+                    if creature["FromIDs"][i] in self.ids:
+                        parent_id = get_id(creature["FromIDs"][i])
+                    else:
+                        if creature["FromIDs"][i] not in merged_with_virtual_parent:
+                            merged_with_virtual_parent.append(creature["FromIDs"][i])
+                        parent_id = get_id("virtual_parent")
+                    inherited = (creature["Inherited"][i] if 'Inherited' in creature else 1)
+                    self.parents[creature_id][parent_id] = inherited
+
+                if "Kind" in creature:
+                    self.kind[creature_id] = creature["Kind"]
+            else:
+                raise LoadingError("[OFFSPRING] misses the 'FromIDs' field!")
 
         # counting the number of expected nodes
-
-        nodes = 0
+        nodes_born, nodes_offspring = 0, 0
         for filename in filenames:
             file = open(filename)
@@ -739,7 +777,11 @@
                         line_arr = line_arr[1].split(' ', 1)
                     if line_arr[0] == "[BORN]":
-                        nodes += 1
-
+                        nodes_born += 1
+                    if line_arr[0] == "[OFFSPRING]":
+                        nodes_offspring += 1
+        # assuming that either BORN or OFFSPRING is present for each individual (as it should...)
+        nodes = max(nodes_born, nodes_offspring)
         nodes = min(nodes, max_nodes if max_nodes != 0 else nodes)+1
+
         self.parents = [{} for x in range(nodes)]
         self.children = [[] for x in range(nodes)]
@@ -776,22 +818,9 @@
                             break
 
-                        creature_id = get_id(creature["ID"])
-
-                        # debug
-                        if loaded_so_far%1000 == 0:
-                            #print(". " + str(creature_id) + " " + str(timelib.time() - lasttime))
-                            lasttime = timelib.time()
-
-                        if "Time" in creature:
-                            self.time[creature_id] = creature["Time"] + time_offset
-                            max_time = max(self.time[creature_id], max_time)
-
-                        for prop in creature:
-                            if prop not in default_props:
-                                if prop not in self.props:
-                                    self.props[prop] = [0 for i in range(nodes)]
-                                self.props[prop][creature_id] = creature[prop]
-
-                        loaded_so_far += 1
+                        if get_id(creature["ID"], False) is None:
+                            loaded_so_far += 1
+
+                        load_born_props(creature)
+                        load_creature_props(creature)
 
                     if line_arr[0] == "[OFFSPRING]":
@@ -801,40 +830,25 @@
                             break
 
-                        if "FromIDs" in creature:
-                            # make sure that ID's of parents are lower than that of their children
-                            for i in range(0, len(creature["FromIDs"])):
-                                if creature["FromIDs"][i] not in self.ids:
-                                    get_id("virtual_parent")
-
-                            creature_id = get_id(creature["ID"])#, False)
-
-                            # we assign to each parent its contribution to the genotype of the child
-                            for i in range(0, len(creature["FromIDs"])):
-                                if creature["FromIDs"][i] in self.ids:
-                                    parent_id = get_id(creature["FromIDs"][i])
-                                else:
-                                    if creature["FromIDs"][i] not in merged_with_virtual_parent:
-                                        merged_with_virtual_parent.append(creature["FromIDs"][i])
-                                    parent_id = get_id("virtual_parent")
-                                inherited = (creature["Inherited"][i] if 'Inherited' in creature else 1)
-                                self.parents[creature_id][parent_id] = inherited
-
-                            if "Kind" in creature:
-                                self.kind[creature_id] = creature["Kind"]
-                        else:
-                            raise LoadingError("[OFFSPRING] misses the 'FromIDs' field!")
-
-                    if line_arr[0] == "[DIED]" or line_arr[0] == "[BORN]":
+                        if get_id(creature["ID"], False) is None:
+                            loaded_so_far += 1
+                            # load time only if there was no [BORN] yet
+                            load_born_props(creature)
+
+                        load_offspring_props(creature)
+
+                    if line_arr[0] == "[DIED]":
                         creature = try_to_load(line_arr[1])
                         if not creature:
                             nodes -= 1
                             break
-                        creature_id = get_id(creature["ID"], False)
-                        if creature_id is not None:
-                            for prop in creature:
-                                if prop not in default_props:
-                                    if prop not in self.props:
-                                        self.props[prop] = [0 for i in range(nodes)]
-                                    self.props[prop][creature_id] = creature[prop]
+                        if get_id(creature["ID"], False) is not None:
+                            load_creature_props(creature)
+                        else:
+                            print("NOTE: entry about the death of individual " + creature["ID"] + " before it was born")
+
+                # debug
+                if loaded_so_far%1000 == 0:
+                    #print(". " + str(creature_id) + " " + str(timelib.time() - lasttime))
+                    lasttime = timelib.time()
 
                 # breaking both loops
