   return x && y && z;
 }
 
-int inside(int3 pos){
+__device__ __host__ int inside(int3 pos){
   int x = (pos.x >= 0 && pos.x < DATA_DIM);
   int y = (pos.y >= 0 && pos.y < DATA_DIM);
   int z = (pos.z >= 0 && pos.z < DATA_DIM);


  //printf("Data created");

  unsigned char* region = grow_region_serial(data);

  //printf("Region grown");


  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 );

  while(finished[0] == 0){
    finished[0] = 1;
    cudaMemcpy( finished_device, finished, sizeof(int), cudaMemcpyHostToDevice);
    region_grow_kernel<<<dimGrid, dimBlock>>>(data_device, region_device, finished_device);
    cudaMemcpy( finished, finished_device, sizeof(int), cudaMemcpyDeviceToHost);
    printf("Finished: %i\n", finished[0]);

  }
  cudaMemcpy( region, region_device, DATA_DIM*DATA_DIM*DATA_DIM*sizeof(unsigned char), cudaMemcpyDeviceToHost);
  return region;
  }

