diff --git a/src/.gdb_history b/src/.gdb_history
index f8384f2e0187d492082bbc7ba9679568bcf30481..4cc2b6dd63a750de8ec9f737fbaa4e496f956a8a 100644
--- a/src/.gdb_history
+++ b/src/.gdb_history
@@ -14,8 +14,6 @@ r
 r
 r
 r
-r
-r
 b main
 r
 n
@@ -254,3 +252,5 @@ r
 r
 r
 r
+r
+r
diff --git a/src/os_threadpool.c b/src/os_threadpool.c
index 388a4f89f69d00f0106facd47fc224547dd853a5..1a4ea5da0e88e3ac7b4f9b615bada5e3eef334e7 100644
--- a/src/os_threadpool.c
+++ b/src/os_threadpool.c
@@ -71,7 +71,7 @@ os_task_t *dequeue_task(os_threadpool_t *tp)
 	os_task_t *t;
 
 	pthread_mutex_lock(&tp->queue_lock);
-	if (queue_is_empty(tp) && tp->active > 0)
+	while (queue_is_empty(tp) && tp->active > 0)
 		pthread_cond_wait(&tp->active_cond, &tp->queue_lock);
 	if (!queue_is_empty(tp)) {
 		t = list_entry(tp->head.next, os_task_t, list);
@@ -89,7 +89,7 @@ static void *thread_loop_function(void *arg)
 	os_threadpool_t *tp = (os_threadpool_t *) arg;
 
 	pthread_mutex_lock(&main_mutex);
-	if (!main_done)
+	while (!main_done)
 		pthread_cond_wait(&main_cond, &main_mutex);
 	pthread_mutex_unlock(&main_mutex);
 	while (1) {
diff --git a/src/parallel.c b/src/parallel.c
index d2d34086a9574439522dfe2b2d9ca916d1f78301..c4c21f85f029e6cf3510abc4dd65ae98a6ace25f 100644
--- a/src/parallel.c
+++ b/src/parallel.c
@@ -25,8 +25,10 @@ void os_destroy_arg(void *arg)
 	free(arg);
 }
 
+static void process_node(unsigned int idx);
+
 /*  Define graph task argument. */
-void process_neighbours(void *arg)
+static void process_neighbours(void *arg)
 {
 	unsigned int idx = *(unsigned int *)arg;
 	os_node_t *node = graph->nodes[idx];
@@ -36,17 +38,9 @@ void process_neighbours(void *arg)
 	pthread_mutex_unlock(&sum_lock);
 
 	pthread_mutex_lock(&graph_lock);
-	for (unsigned int i = 0; i < node->num_neighbours; ++i) {
-		if (graph->visited[node->neighbours[i]] == NOT_VISITED) {
-			graph->visited[node->neighbours[i]] = DONE;
-			unsigned int *new_arg = malloc(sizeof(unsigned int));
-
-			*new_arg = node->neighbours[i];
-			os_task_t *new_task = create_task(process_neighbours, (void *)new_arg, os_destroy_arg);
-
-			enqueue_task(tp, new_task);
-		}
-	}
+	for (unsigned int i = 0; i < node->num_neighbours; ++i)
+		if (graph->visited[node->neighbours[i]] == NOT_VISITED)
+			process_node(node->neighbours[i]);
 	pthread_mutex_unlock(&graph_lock);
 }