diff --git a/GNUmakefile b/GNUmakefile
index 957f088f426b8abd88a3bbf060338ea550fa404a..93d0a944654783d8401cc4b40f3778fef6e0388e 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -13,7 +13,7 @@ src_test_set_max_speed = test_set_max_speed.f derived_types.f set_max_speed.f go
 
 src_test_get_snapshot = test_get_snapshot.f get_snapshot.f dispatch_snapshot.f write_eddy.f send_snapshot.f receive_snapshot.f local_extrema.f set_max_speed.f outermost_possible_level.f get_1_outerm.f max_speed_contour_ssh.f good_contour.f spherical_polyline_area.f mean_speed.f inside_4.f set_all_outerm.f derived_types.f init_shapefiles.f nearby_extr.f
 
-src_test_set_all_outerm = test_set_all_outerm.f derived_types.f set_all_outerm.f local_extrema.f get_1_outerm.f good_contour.f spherical_polyline_area.f
+src_test_set_all_outerm = test_set_all_outerm.f derived_types.f set_all_outerm.f local_extrema.f get_1_outerm.f good_contour.f spherical_polyline_area.f nearby_extr.f
 
 src_test_weight = test_weight.f weight.f derived_types.f
 
diff --git a/depend.mk b/depend.mk
index c938ee8f15a103dee1b1157e462efac4434f2162..cb45f304b3154896cc8753b4dcc4b8668229029a 100644
--- a/depend.mk
+++ b/depend.mk
@@ -6,7 +6,7 @@ read_eddy.o : derived_types.o
 read_snapshot.o : read_eddy.o derived_types.o 
 receive_snapshot.o : derived_types.o 
 send_snapshot.o : derived_types.o 
-set_all_outerm.o : local_extrema.o get_1_outerm.o derived_types.o 
+set_all_outerm.o : local_extrema.o nearby_extr.o get_1_outerm.o derived_types.o 
 set_max_speed.o : spherical_polyline_area.o mean_speed.o max_speed_contour_ssh.o inside_4.o good_contour.o derived_types.o 
 spherical_polygon_area.o : spherical_polyline_area.o 
 successive_overlap.o : weight.o spherical_polyline_area.o spherical_polygon_area.o derived_types.o 
diff --git a/set_all_outerm.f b/set_all_outerm.f
index e4cf22b984d38de5fa35e0ed84b0259bdb0e17e9..f462cdc9ba5954259434237a1802a46483c9b3a0 100644
--- a/set_all_outerm.f
+++ b/set_all_outerm.f
@@ -10,10 +10,9 @@ contains
     ! contours in snapshot. Not a function because snapshot is not
     ! completely defined.
 
-    use contour_531, only: convert_to_reg_coord
     use derived_types, only: snapshot
     use get_1_outerm_m, only: get_1_outerm
-    use jumble, only: argwhere
+    use nearby_extr_m, only: nearby_extr
     use local_extrema_m, only: local_extrema
 
     type(snapshot), intent(out):: s
@@ -57,10 +56,6 @@ contains
     real, allocatable:: corner_window(:, :) ! (2, s%number_vis_eddies)
     ! longitude and latitude, in rad
 
-    real, allocatable:: nearby_extr(:, :) ! (2, :) longitude and
-    ! latitude, in rad, of all the significant extrema, except the
-    ! target extremum
-
     !--------------------------------------------------------------
 
     nlon = size(ssh, 1)
@@ -92,12 +87,10 @@ contains
 
     do i = 1, s%number_vis_eddies
        if (flat_extr(i)) then
-          nearby_extr &
-               = convert_to_reg_coord(argwhere(s%extr_map(llc(1, i):urc(1, i), &
-               llc(2, i):urc(2, i)) > 0 .and. s%extr_map(llc(1, i):urc(1, i), &
-               llc(2, i):urc(2, i)) /= i), corner_window(:, i), step)
           s%list_vis(i)%out_cont = get_1_outerm(s%list_vis(i)%cyclone, &
-               s%list_vis(i)%coord_extr, innermost_level(i), nearby_extr, &
+               s%list_vis(i)%coord_extr, innermost_level(i), &
+               nearby_extr(s%extr_map(llc(1, i):urc(1, i), &
+               llc(2, i):urc(2, i)), s%list_vis, i), &
                ssh(llc(1, i):urc(1, i), llc(2, i):urc(2, i)), &
                corner_window(:, i), step)
           if (s%list_vis(i)%out_cont%n_points == 0) then
@@ -132,12 +125,10 @@ contains
     do i = 1, s%number_vis_eddies
        if (s%list_vis(i)%suff_amp .and. noise_around(i) &
             .or. .not. flat_extr(i)) then
-          nearby_extr &
-               = convert_to_reg_coord(argwhere(s%extr_map(llc(1, i):urc(1, i), &
-               llc(2, i):urc(2, i)) > 0 .and. s%extr_map(llc(1, i):urc(1, i), &
-               llc(2, i):urc(2, i)) /= i), corner_window(:, i), step)
           s%list_vis(i)%out_cont = get_1_outerm(s%list_vis(i)%cyclone, &
-               s%list_vis(i)%coord_extr, innermost_level(i), nearby_extr, &
+               s%list_vis(i)%coord_extr, innermost_level(i), &
+               nearby_extr(s%extr_map(llc(1, i):urc(1, i), &
+               llc(2, i):urc(2, i)), s%list_vis, i), &
                ssh(llc(1, i):urc(1, i), llc(2, i):urc(2, i)), &
                corner_window(:, i), step)
           s%list_vis(i)%suff_amp = s%list_vis(i)%out_cont%n_points /= 0