diff --git a/Trajectories/cost_function.py b/Trajectories/cost_function.py
index 6687be53fce3b59bec26917717b577ba6f037dfa..aa293b8447e19fb2f43ed065ab538e86ad0d98ca 100755
--- a/Trajectories/cost_function.py
+++ b/Trajectories/cost_function.py
@@ -176,13 +176,16 @@ if args.debug:
 
 g.ep["cost_function"] = g.new_ep("float")
 SHPC = util_eddies.SHPC_class(args.SHPC_dir, args.orientation)
-n_days_avg = 7  # number of days to average, must be >= 1
+
+max_delta = 6
+# maximum distance in number of eddies, over which we average, must be >= 0
+
 print("Iterating on vertices...")
 
 for n in g.vertices():
     if n.in_degree() != 0:
         # Define properties for beginning of the segment:
-        ip_beg = search_beg(g.vp.inst_eddies[n], n_days_avg - 1)
+        ip_beg = search_beg(g.vp.inst_eddies[n], max_delta)
         properties = node_to_prop(
             g.vp.inst_eddies[n][:ip_beg],
             g.gp.e_overestim,
@@ -202,7 +205,7 @@ for n in g.vertices():
         if ip_beg < len_seg:
             # We have to read more from the shapefiles and redefine
             # properties.
-            ip_end = search_end(g.vp.inst_eddies[n], n_days_avg - 1)
+            ip_end = search_end(g.vp.inst_eddies[n], max_delta)
 
             if ip_beg <= ip_end:
                 # We cannot use part of properties from the beginning