diff --git a/Trajectories/cost_function.py b/Trajectories/cost_function.py
index aa293b8447e19fb2f43ed065ab538e86ad0d98ca..b9bfa1abfc701a82ce1c04a7e134c470c359034d 100755
--- a/Trajectories/cost_function.py
+++ b/Trajectories/cost_function.py
@@ -200,9 +200,7 @@ for n in g.vertices():
     if n.out_degree() != 0:
         # Define properties for end of the segment:
 
-        len_seg = len(g.vp.inst_eddies[n])
-
-        if ip_beg < len_seg:
+        if ip_beg < len(g.vp.inst_eddies[n]):
             # We have to read more from the shapefiles and redefine
             # properties.
             ip_end = search_end(g.vp.inst_eddies[n], max_delta)
@@ -217,7 +215,7 @@ for n in g.vertices():
                     args.orientation,
                 )
             else:
-                # assertion: ip_end < ip_beg < len_seg
+                # assertion: ip_end < ip_beg < len(g.vp.inst_eddies[n])
 
                 # We can use part of the properties from the beginning
                 # of the segment.