diff --git a/examples/test_qr_mpi.c b/examples/test_qr_mpi.c
index 2a235235fee9146fbc9b8e82169b189b07b888fa..6711a95a92740eb069fabb386f73ac8b4db0c4ac 100644
--- a/examples/test_qr_mpi.c
+++ b/examples/test_qr_mpi.c
@@ -664,7 +664,7 @@ if(s.rank == 0) {
             memcpy(rids[k*m+i], &A_orig[(data[1]*m+data[0])*K*K], sizeof(double)*K*K);
         }
       qsched_addlock(&s, tid_new, rid[k * m + i]);
-      qsched_adduse(&s, tid_new, rid[k * m + k]);
+      qsched_addlock(&s, tid_new, rid[k * m + k]);
       qsched_addlock(&s, tid_new, tau_id[k*m+i]);
       qsched_addunlock(&s, tid[k * m + (i - 1)], tid_new);
       if (tid[k * m + i] != -1) qsched_addunlock(&s, tid[k * m + i], tid_new);
diff --git a/src/qsched.c b/src/qsched.c
index 0692040e8eec9e8a28164ad74e47a24c0380bc8c..d816baf957b206134cdc158ac1fe5b5f21a076ec 100644
--- a/src/qsched.c
+++ b/src/qsched.c
@@ -2409,10 +2409,11 @@ for(i = 0; i < count; i++)
     /*Find the parents. */
     num_parents = 0;
     int max = wait_init[gettaskindex(t->id, s)];
+//    for(j = i-1; j >= 0 && num_parents < max; j--)
     for(j = 0; j < i && num_parents < max; j++)
     {
-        struct task *t2 = &s->tasks[gettaskindex(tid[j], s)];
-        int nr_un = t2->nr_unlocks;
+        const struct task *t2 = &s->tasks[gettaskindex(tid[j], s)];
+        const int nr_un = t2->nr_unlocks;
         for(k = 0; k < nr_un; k++)
         {
             if(t2->unlocks[k] == ttid)
@@ -2431,6 +2432,7 @@ for(i = 0; i < count; i++)
                     memcpy(temp, parents, sizeof(int) * num_parents);
                     free(parents);
                     parents = temp;
+                    message("Extended parents array");
                 }
                 parents[num_parents++] = j;//We're storing the index in the topological order for parents -- maybe should just be ID?
                 break;
@@ -2443,17 +2445,19 @@ for(i = 0; i < count; i++)
     /* Loop over the locked resources */
     for(j = 0; j < t->nr_locks; j++)
     {
-            int lock_index = getindex(t->locks[j],s);
-            struct res *res = &s->res[lock_index];
+        const int lock_index = getindex(t->locks[j],s);
+        struct res *res = &s->res[lock_index];
 
 
         if(res->node == s->rank)
             continue;
+
+
         /* Find the parents that unlock this resource. */
         num_current = 0;
         int num_skipped = 0;
         int last_index = -1;
-        int tlock = t->locks[j];
+        const int tlock = t->locks[j];
         for(k = num_parents-1; k >= 0; k--)
         {
 
@@ -2625,7 +2629,7 @@ for(i = 0; i < count; i++)
                     }
                     /* All the parents of this task are completed before the send task can occur also!*/            
                     int found = 0;
-                    struct task *temp = &ts.tasks[(send_task[getindex(t->locks[j], s)] & 0xFFFFFFFFF) - ts.id_count];
+                    const struct task *temp = &ts.tasks[(send_task[getindex(t->locks[j], s)] & 0xFFFFFFFFF) - ts.id_count];
                     for(l = 0; l < temp->nr_unlocks; l++)
                     {
                         if(temp->unlocks[l] == tid[current_parents[k]] && ts.deps_key[l] == t->locks[j])
@@ -2659,7 +2663,7 @@ for(i = 0; i < count; i++)
     for(j = 0; j < t->nr_uses; j++)
     {
 
-        int use_index = getindex(t->uses[j],s);
+        const int use_index = getindex(t->uses[j],s);
         struct res *res = &s->res[use_index];
         if(res->node == s->rank)
             continue;
@@ -2839,7 +2843,7 @@ for(i = 0; i < count; i++)
                     message("send_task = %lli", send_task[getindex(t->uses[j], s)]);
                     message("send_task & 0xFFFFFFFFF = %lli", send_task[getindex(t->uses[j], s)] & 0xFFFFFFFFF);
                     message("j=%i, i = %i, k = %i", j, i, k);*/
-                    struct task *temp = &ts.tasks[(send_task[use_index] & 0xFFFFFFFFF) - ts.id_count];
+                    const struct task *temp = &ts.tasks[(send_task[use_index] & 0xFFFFFFFFF) - ts.id_count];
 //                    for(l = 0; l < temp->nr_unlocks; l++)
                     for(l = 0; l < ts.count_unlockers; l++)
                     {
@@ -3743,7 +3747,6 @@ printf("Rank[%i]: qsched_prepare_mpi took %lli (= %.3fms) ticks\n", s->rank,
             error( "Failed to create pthread." );
         #if defined( HAVE_LIBNUMA)
         CPU_ZERO(&cpuset);
-#define SHMEM
         #ifdef SHMEM
         CPU_SET(cpuid[tid+s->rank], &cpuset);
         #else
@@ -4344,7 +4347,7 @@ int qsched_locktask ( struct qsched *s , long long int tid ) {
 #ifdef WITH_MPI
     /* Check the status of the MPI request. */
     int res, err;
-    MPI_Status stat;
+    MPI_Status stat;    
     if ((err = MPI_Test(&t->req, &res, &stat)) != MPI_SUCCESS) {
       char buff[MPI_MAX_ERROR_STRING];
       int len;