   clock_t start, diff;
   
   // Size of array.
-  unsigned int SIZE = pow(2,25);
+  unsigned int SIZE = (unsigned int)pow(2, 21);// 65536;// 65025;// / 2;//(unsigned int)pow(2,25);
+  //unsigned int SIZE = 1024;// (unsigned int)pow(2, 20);
+
+  /*
+  // Possibly used to automate the SIZE value. For now, I found 2^21 to give good results 
+  size_t availableMemory, totalMemory, usedMemory;
+
+  cudaMemGetInfo(&availableMemory, &totalMemory);
+  usedMemory = totalMemory - availableMemory;
+  */
+
+
+  int blockSize;   // The launch configurator returned block size 
+  int minGridSize; // The minimum grid size needed to achieve the 
+				   // maximum occupancy for a full device launch 
+  int gridSize;    // The actual grid size needed, based on input size 
+
 
   // Sailors and monkeys
-  unsigned int monkeys = 1;
-  unsigned int max_sailors = 9;
+  unsigned char monkeys = 1;
+  unsigned char max_sailors = 9;
 
   // CPU memory pointers
   unsigned long long int *h_coc, da_solu=1;
   unsigned int *h_found, *h_solutions, *h_tot;
 
   // GPU memory pointers
-  unsigned long long int *d_coc, extra = 0;
+  unsigned long long int extra = 0;
   unsigned int *d_found, *d_solutions, *d_tot;
 
   // Allocate the space, CPU

  //cudamemset can be used for initializing data (say, all zeros). 10 times faster than cudaMemcpy zero array because it is done on the gpu directly.
  cudaMemset(d_solutions, 0, SIZE*sizeof(unsigned int));

  // Start timer
  start = clock();

  // Run the loop 
  for (unsigned int sailors=2; sailors<max_sailors+1;sailors++){

    printf("Running %u sailors, %u monkeys\n", sailors, monkeys);


}


__global__ 
void monkey(unsigned int *tot, unsigned long long int extra, unsigned int *the_solutions, unsigned int *found, unsigned int sailors, unsigned int monkeys, unsigned int n)
{
  if (found[0] == 0){

    for (unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; i<n; i+=blockDim.x*gridDim.x){

	  unsigned char j;
	  const unsigned long long int rExtra = extra;
	  unsigned int rCoconuts = tot[i] + rExtra;
	  const unsigned int rSailors = sailors;
	  const unsigned int rMonkeys = monkeys;

      // Go through the number of sailors
      for (j=0; j<rSailors;j++){
        // One for each monkey
		  rCoconuts -= rMonkeys;
        if (rCoconuts % rSailors != 0){
          break;
        }     
		rCoconuts -= rCoconuts/ rSailors;
      }
      if (rCoconuts % rSailors == 0){
        found[0] = 1;
        the_solutions[i] = i;
/*
