 }
 
 
+// This function loads data and region into the texture memory of the gpu. After the data is loaded
+// it run a thread on the gpu for each pixel in the image. After all threads are done
+// the finished image is loaded from the gpu to the main memory.
+// TODO: Find the bug that make this output a few random cubes.
 unsigned char* raycast_gpu_texture(unsigned char* data, unsigned char* region){
   unsigned char* image = (unsigned char*)malloc(sizeof(unsigned char)*IMAGE_DIM*IMAGE_DIM);
 
-  //unsigned char *data_device;
-  //unsigned char *region_device;
   unsigned char* image_device;
-  //cudaMalloc( (void**)&data_device, DATA_DIM*DATA_DIM*DATA_DIM*sizeof(unsigned char));
-  //cudaMalloc( (void**)&region_device, DATA_DIM*DATA_DIM*DATA_DIM*sizeof(unsigned char));
   cudaMalloc( (void**)&image_device,DATA_DIM*DATA_DIM*sizeof(unsigned char));
-  //cudaMemcpy( data_device, data, DATA_DIM*DATA_DIM*DATA_DIM*sizeof(unsigned char), cudaMemcpyHostToDevice);
-  //cudaMemcpy( region_device, region, DATA_DIM*DATA_DIM*DATA_DIM*sizeof(unsigned char), cudaMemcpyHostToDevice);
   cudaMemcpy( image_device, image, DATA_DIM*DATA_DIM*sizeof(unsigned char), cudaMemcpyHostToDevice);
-
-
 
   data_texture.filterMode=cudaFilterModePoint;
   data_texture.addressMode[0]=cudaAddressModeWrap; 

  cudaMalloc( (void**)&finished_device, sizeof(int));
  cudaMemcpy( data_device, data, DATA_DIM*DATA_DIM*DATA_DIM*sizeof(unsigned char), cudaMemcpyHostToDevice);
  cudaMemcpy( region_device, region, DATA_DIM*DATA_DIM*DATA_DIM*sizeof(unsigned char), cudaMemcpyHostToDevice);
  //cudaMemcpy( finished_device, finished, sizeof(int), cudaMemcpyHostToDevice);

  dim3 dimBlock( 8, 8, 8 );
  dim3 dimGrid( 64, 64, 64 );

    }
  }
  region[pixel.z * DATA_DIM*DATA_DIM + pixel.y*DATA_DIM + pixel.x] = shared_region[pixel.z * DATA_DIM*DATA_DIM + pixel.y*DATA_DIM + pixel.x];
}

// This function creates an empty region and upload it and the data to the gpu.
// When the data is ready it will launch a thread on the gpu for each point in
// the region. The threads will run 40 iterations each before terminating.
// The cpu will then check if there was any extended borders during the execution,
// and run 40 new iterations until there is no updates.
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));
