diff --git a/src/engine_maketasks.c b/src/engine_maketasks.c
index c8606fe2812c34098bb39a5af1de0081664865d9..28db5daedc87f8fd4e8d40adc7656f0e6f0214f8 100644
--- a/src/engine_maketasks.c
+++ b/src/engine_maketasks.c
@@ -1493,22 +1493,21 @@ void engine_count_and_link_tasks_mapper(void *map_data, int num_elements,
     /* Link sort tasks to all the higher sort task. */
     if (t_type == task_type_sort) {
       for (struct cell *finger = t->ci->parent; finger != NULL;
-           finger = finger->parent)
+           finger = finger->parent) {
         if (finger->hydro.sorts != NULL)
           scheduler_addunlock(sched, t, finger->hydro.sorts);
-    }
+      }
 
-    /* Link stars sort tasks to all the higher sort task. */
-    if (t_type == task_type_stars_sort) {
+      /* Link stars sort tasks to all the higher sort task. */
+    } else if (t_type == task_type_stars_sort) {
       for (struct cell *finger = t->ci->parent; finger != NULL;
            finger = finger->parent) {
         if (finger->stars.sorts != NULL)
           scheduler_addunlock(sched, t, finger->stars.sorts);
       }
-    }
 
-    /* Link self tasks to cells. */
-    else if (t_type == task_type_self) {
+      /* Link self tasks to cells. */
+    } else if (t_type == task_type_self) {
       atomic_inc(&ci->nr_tasks);
 
       if (t_subtype == task_subtype_density) {