   int32_t c1, c2, c3;
   float plane_a,plane_b,plane_c,plane_d;
 
-
-  // CUDA copy over needed memory information
-  // disparity_grid, I1_desc,I2_desc,P,D
-  int32_t* d_disparity_grid, *d_grid_dims;
-  int32_t* d_P;
-  float* d_D;
-  uint8_t* d_I1, *d_I2;
-  //Allocate on global memory
-  cudaMalloc((void**) &d_disparity_grid, grid_dims[0]*grid_dims[1]*grid_dims[2]*sizeof(int32_t));
-  cudaMalloc((void**) &d_P, disp_num*sizeof(int32_t));
-  cudaMalloc((void**) &d_D, width*height*sizeof(float));
-  cudaMalloc((void**) &d_I1, 16*width*height*sizeof(uint8_t)); //Device descriptors
-  cudaMalloc((void**) &d_I2, 16*width*height*sizeof(uint8_t)); //Device descriptors
-  cudaMalloc((void**) &d_grid_dims, 3*sizeof(int32_t)); 
-
-  //Now copy over data
-  cudaMemcpy(d_disparity_grid, disparity_grid, grid_dims[0]*grid_dims[1]*grid_dims[2]*sizeof(int32_t), cudaMemcpyHostToDevice);
-  cudaMemcpy(d_P, P, disp_num*sizeof(int32_t), cudaMemcpyHostToDevice);
-  cudaMemcpy(d_D, D, width*height*sizeof(float), cudaMemcpyHostToDevice);
-  cudaMemcpy(d_I1, I1_desc, 16*width*height*sizeof(uint8_t), cudaMemcpyHostToDevice);
-  cudaMemcpy(d_I2, I2_desc, 16*width*height*sizeof(uint8_t), cudaMemcpyHostToDevice);
-  cudaMemcpy(d_grid_dims, grid_dims, 3*sizeof(int32_t), cudaMemcpyHostToDevice); 
+  // Size variables
+  int32_t size_total = 0;
+  int32_t size_tri = tri.size();
+
+  // Master objects that will need to be created
+  // These will be passed to the CUDA kernel
+  float* planes = new float[4*size_tri];
+  int32_t* size_uv = new int32_t[size_tri];
+  int32_t** vals_u = new *int32_t[size_tri];
+  int32_t** vals_v = new *int32_t[size_tri];
+
 
   // for all triangles do
   for (uint32_t i=0; i<tri.size(); i++) {

  uint32_t idx = blockDim.x*blockIdx.x + threadIdx.x;

  // Check that we are in range
  if(idx >= size_vals)
    return;

  // Else get our value
  uint32_t u = u_vals[idx];
  uint32_t v = v_vals[idx];

  // address of disparity we want to compute
  uint32_t d_addr;

    bool valid = fabs(plane_a)<0.7 && fabs(plane_d)<0.7;

    // Vector of all u,v pairs we need to calculate
    std::vector<int32_t> temp_val_u = new std::vector<int32_t>();
    std::vector<int32_t> temp_val_v = new std::vector<int32_t>();
        
    // first part (triangle corner A->B)
    if ((int32_t)(A_u)!=(int32_t)(B_u)) {
