diff --git a/src/cell.c b/src/cell.c
index 3a0e99fd5e3a489734e05998d1cb32155e620544..cd2f2d6b86e2301b2e675f442ed9a6790ab223eb 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -41,6 +41,7 @@
 
 /* Local headers. */
 #include "const.h"
+#include "atomic.h"
 #include "cycle.h"
 #include "lock.h"
 #include "task.h"
@@ -232,7 +233,7 @@ int cell_locktree( struct cell *c ) {
             break;
             
         /* Increment the hold. */
-        __sync_fetch_and_add( &finger->hold , 1 );
+        atomic_inc( &finger->hold );
         
         /* Unlock the cell. */
         if ( lock_unlock( &finger->lock ) != 0 )
@@ -475,7 +476,8 @@ void cell_split ( struct cell *c  ) {
         
     /* Re-link the gparts. */
     for ( k = 0 ; k < count ; k++ )
-        parts[k].gpart->part = &parts[k];
+        if ( parts[k].gpart != NULL )
+            parts[k].gpart->part = &parts[k];
         
     /* Verify that _all_ the parts have been assigned to a cell. */
     /* for ( k = 1 ; k < 8 ; k++ )
diff --git a/src/const.h b/src/const.h
index 7d6f5c12e67abc4b5fe3719aea496088e97ddd58..776e85a38ad3165dbd31d5406713fa9272634daa 100644
--- a/src/const.h
+++ b/src/const.h
@@ -1,6 +1,6 @@
 /*******************************************************************************
  * This file is part of SWIFT.
- * Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
+ * Coypright (c) 2012 Pedro Gonnet (ptcedro.gonnet@durham.ac.uk)
  *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
  * 
  * This program is free software: you can redistribute it and/or modify
@@ -44,9 +44,12 @@
 /* Gravity stuff. */
 #define const_theta_max         0.57735f        /* Opening criteria, which is the ratio of the
                                                    cell distance over the cell width. */
-#define const_G                 6.67384e-8f     /* Gravitational constant. */
-#define const_epsilon           0.0014f         /* Gravity blending distance. */
-#define const_iepsilon          714.285714286f  /* Inverse gravity blending distance. */
+// #define const_G                 6.67384e-8f     /* Gravitational constant. */
+#define const_G                 6.672e-8f     /* Gravitational constant. */
+// #define const_epsilon           0.0014f         /* Gravity blending distance. */
+// #define const_iepsilon          714.285714286f  /* Inverse gravity blending distance. */
+#define const_epsilon 1e-20
+#define const_iepsilon 1e20
 #define const_iepsilon2         (const_iepsilon*const_iepsilon)
 #define const_iepsilon3         (const_iepsilon2*const_iepsilon)
 #define const_iepsilon4         (const_iepsilon2*const_iepsilon2)
diff --git a/src/engine.c b/src/engine.c
index 3a40b91b968342afac18223761c446855491313b..5e027e0b70b0d5c18debe036851531e39f36bf4b 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -963,11 +963,13 @@ void engine_maketasks ( struct engine *e ) {
                 }
                 
     /* Add the gravity mm tasks. */
-    for ( i = 0 ; i < nr_cells ; i++ ) {
-        scheduler_addtask( sched , task_type_grav_mm , task_subtype_none , -1 , 0 , &cells[i] , NULL , 0 );
-        for ( j = i+1 ; j < nr_cells ; j++ )
-            scheduler_addtask( sched , task_type_grav_mm , task_subtype_none , -1 , 0 , &cells[i] , &cells[j] , 0 );
-        }
+    for ( i = 0 ; i < nr_cells ; i++ )
+        if ( cells[i].gcount > 0 ) {
+            scheduler_addtask( sched , task_type_grav_mm , task_subtype_none , -1 , 0 , &cells[i] , NULL , 0 );
+            for ( j = i+1 ; j < nr_cells ; j++ )
+                if ( cells[j].gcount > 0 )
+                    scheduler_addtask( sched , task_type_grav_mm , task_subtype_none , -1 , 0 , &cells[i] , &cells[j] , 0 );
+            }
         
     /* Split the tasks. */
     scheduler_splittasks( sched );
@@ -981,7 +983,7 @@ void engine_maketasks ( struct engine *e ) {
     
     /* Add the gravity up/down tasks at the top-level cells and push them down. */
     for ( k = 0 ; k < nr_cells ; k++ )
-        if ( cells[k].nodeID == nodeID ) {
+        if ( cells[k].nodeID == nodeID && cells[k].gcount > 0 ) {
         
             /* Create tasks at top level. */
             struct task *up = scheduler_addtask( sched , task_type_grav_up , task_subtype_none , 0 , 0 , &cells[k] , NULL , 0 );
@@ -1131,7 +1133,7 @@ void engine_maketasks ( struct engine *e ) {
             }
             
         /* Kick2 tasks should rely on the grav_down tasks of their cell. */
-        else if ( t->type == task_type_kick2 )
+        else if ( t->type == task_type_kick2 && t->ci->grav_down != NULL )
             scheduler_addunlock( sched , t->ci->grav_down , t );
             
         }
diff --git a/src/part.h b/src/part.h
index ce87cfcabb3170c97723c8afeedcfd3d5fd8e37b..3e8f5891b15677faeca01b20a2edacd6e97481ab 100644
--- a/src/part.h
+++ b/src/part.h
@@ -68,7 +68,7 @@ struct gpart {
     union {
     
         /* Particle ID. */
-        unsigned long long id;
+        size_t id;
 
         /* Pointer to corresponding SPH part. */
         struct part *part;
diff --git a/src/queue.c b/src/queue.c
index ff161fbdd35c8b3dc2afee0f45184ddedc3b240d..b066057c5e841a605ea020299f63f725aaeaf54e 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -152,7 +152,7 @@ void queue_init ( struct queue *q , struct task *tasks ) {
  
 struct task *queue_gettask ( struct queue *q , struct cell *super , int blocking ) {
 
-    int k, temp, qcount, *qtid, gotcha;
+    int k, qcount, *qtid, gotcha;
     lock_type *qlock = &q->lock;
     struct task *qtasks, *res = NULL;
     
@@ -216,7 +216,8 @@ struct task *queue_gettask ( struct queue *q , struct cell *super , int blocking
         /* Swap this task with the last task and re-heap. */
         if ( k < qcount ) {
             qtid[ k ] = qtid[ qcount ];
-            while ( qtasks[ qtid[k] ].weight > qtasks[ qtid[(k-1)/2] ].weight ) {
+            int w = qtasks[ qtid[k] ].weight;
+            while ( k > 0 && w > qtasks[ qtid[(k-1)/2] ].weight ) {
                 int temp = q->tid[k];
                 q->tid[k] = q->tid[(k-1)/2];
                 q->tid[(k-1)/2] = temp;
@@ -226,8 +227,8 @@ struct task *queue_gettask ( struct queue *q , struct cell *super , int blocking
             while ( ( i = 2*k+1 ) < qcount ) {
                 if ( i+1 < qcount && qtasks[ qtid[i+1] ].weight > qtasks[ qtid[i] ].weight )
                     i += 1;
-                if ( qtasks[ qtid[i] ].weight > qtasks[ qtid[k] ].weight ) {
-                    temp = qtid[i];
+                if ( qtasks[ qtid[i] ].weight > w ) {
+                    int temp = qtid[i];
                     qtid[i] = qtid[k];
                     qtid[k] = temp;
                     k = i;
diff --git a/src/scheduler.c b/src/scheduler.c
index 10fb22171fce6f13c5c1862807938a18a0f293bb..687aa5a616662eb57f740f072edc6c2d0ebf2895 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -464,7 +464,7 @@ void scheduler_splittasks ( struct scheduler *s ) {
                         /* Split this task into tasks on its progeny. */
                         t->type = task_type_none;
                         for ( j = 0 ; j < 8 ; j++ )
-                            if ( ci->progeny[j] != NULL ) {
+                            if ( ci->progeny[j] != NULL && ci->progeny[j]->gcount > 0 ) {
                                 if ( t->type == task_type_none ) {
                                     t->type = task_type_grav_mm;
                                     t->ci = ci->progeny[j];
@@ -473,7 +473,7 @@ void scheduler_splittasks ( struct scheduler *s ) {
                                 else
                                     t = scheduler_addtask( s , task_type_grav_mm , task_subtype_none , 0 , 0 , ci->progeny[j] , NULL , 0 );
                                 for ( k = j+1 ; k < 8 ; k++ )
-                                    if ( ci->progeny[k] != NULL ) {
+                                    if ( ci->progeny[k] != NULL && ci->progeny[k]->gcount > 0 ) {
                                         if ( t->type == task_type_none ) {
                                             t->type = task_type_grav_mm;
                                             t->ci = ci->progeny[j];
@@ -534,9 +534,9 @@ void scheduler_splittasks ( struct scheduler *s ) {
                             /* Split this task into tasks on its progeny. */
                             t->type = task_type_none;
                             for ( j = 0 ; j < 8 ; j++ )
-                                if ( ci->progeny[j] != NULL ) {
+                                if ( ci->progeny[j] != NULL && ci->progeny[j]->gcount > 0 ) {
                                     for ( k = 0 ; k < 8 ; k++ )
-                                        if ( cj->progeny[k] != NULL ) {
+                                        if ( cj->progeny[k] != NULL && cj->progeny[k]->gcount > 0 ) {
                                             if ( t->type == task_type_none ) {
                                                 t->type = task_type_grav_mm;
                                                 t->ci = ci->progeny[j];
diff --git a/src/space.c b/src/space.c
index e0bd071626006b08ea3a650548f3b344e065e0ef..16a213e8a2e56a2fab54cf8fb361b4cae83010a4 100644
--- a/src/space.c
+++ b/src/space.c
@@ -1163,7 +1163,7 @@ void space_init ( struct space *s , double dim[3] , struct part *parts , int N ,
     if ( posix_memalign( (void *)&s->gparts , part_align , N * sizeof(struct gpart) ) != 0 )
         error( "Failed to allocate gparts." );
     bzero( s->gparts , N * sizeof(struct gpart) );
-    for ( int k = 0 ; k < N ; k++ ) {
+    /* for ( int k = 0 ; k < N ; k++ ) {
         s->gparts[k].x[0] = s->parts[k].x[0];
         s->gparts[k].x[1] = s->parts[k].x[1];
         s->gparts[k].x[2] = s->parts[k].x[2];
@@ -1176,7 +1176,8 @@ void space_init ( struct space *s , double dim[3] , struct part *parts , int N ,
         s->gparts[k].part = &s->parts[k];
         s->parts[k].gpart = &s->gparts[k];
         }
-    s->nr_gparts = s->nr_parts;
+    s->nr_gparts = s->nr_parts; */
+    s->nr_gparts = 0;
     s->size_gparts = s->size_parts;