 
 
 __global__ void region_grow_kernel(unsigned char* data, unsigned char* region, int* finished){
-  unsigned char* region = (unsigned char*)calloc(sizeof(unsigned char), DATA_DIM*DATA_DIM*DATA_DIM);
-
-  int x = blockIdx.x * blockDim + threadIdx.x;
-  int y = blockIdx.y * blockDim + threadIdx.y;
-  int z = blockIdx.z * blockDim + threadIdx.z;
+  int x = blockIdx.x * blockDim.x + threadIdx.x;
+  int y = blockIdx.y * blockDim.y + threadIdx.y;
+  int z = blockIdx.z * blockDim.z + threadIdx.z;
 
   int dx[6] = {-1,1,0,0,0,0};
   int dy[6] = {0,0,-1,1,0,0};
   int dz[6] = {0,0,0,0,-1,1};
 
-  int3 pixel = {.x=x .y=y .z=z};
+  int3 pixel = {.x=x, .y=y, .z=z};
   if(region[pixel.z * DATA_DIM*DATA_DIM + pixel.y*DATA_DIM + pixel.x]==2){
-    region[candidate.z * DATA_DIM*DATA_DIM + candidate.y*DATA_DIM + candidate.x] = 1;
+    region[pixel.z * DATA_DIM*DATA_DIM + pixel.y*DATA_DIM + pixel.x] = 1;
     for(int n = 0; n < 6; n++){
       int3 candidate = pixel;
       candidate.x += dx[n];

unsigned char* grow_region_gpu(unsigned char* data){
  unsigned char* region = (unsigned char*)calloc(sizeof(unsigned char), DATA_DIM*DATA_DIM*DATA_DIM);
  int* finished = (int*)malloc(sizeof(int));
  finished[0] = 1;

  int3 seed = {.x=50, .y=300, .z=300};
  region[seed.z *DATA_DIM*DATA_DIM + seed.y*DATA_DIM + seed.x] = 2;



// Check if two values are similar, threshold can be changed.
__device__ __host__ int similar(unsigned char* data, int3 a, int3 b){
  unsigned char va = data[a.z * DATA_DIM*DATA_DIM + a.y*DATA_DIM + a.x];
  unsigned char vb = data[b.z * DATA_DIM*DATA_DIM + b.y*DATA_DIM + b.x];

