   return ((double)tp.tv_sec + (double)tp.tv_nsec*1.e-9);
 }
 
-void generateImage(int width, int height, Offset offset, int maxThreads, const char* filename, bool quiet) {
+void generateImage(int width, int height, Offset offset, int threadsX, int threadsY, const char* filename, bool quiet) {
   Bitmap bitmap(width, height);
 
   size_t pixelsCount = bitmap.width * bitmap.height;
   size_t pixelsSize = pixelsCount * sizeof(Pixel);
   cudaMalloc(&bitmap.pixels, pixelsSize);
 
-  int threadsPerBlock1dim, numBlocksX, numBlocksY;
-  threadConfigCalc(maxThreads, threadsPerBlock1dim, numBlocksX, numBlocksY, quiet);
-
-  dim3 threadsPerBlock(threadsPerBlock1dim, threadsPerBlock1dim);
+  int threadsPerBlock1dim1, threadsPerBlock1dim2, numBlocksX, numBlocksY;
+  threadConfigCalc(threadsX, threadsY, bitmap.width, bitmap.height, threadsPerBlock1dim1, threadsPerBlock1dim2, numBlocksX, numBlocksY, quiet);
+
+  dim3 threadsPerBlock(threadsPerBlock1dim1, threadsPerBlock1dim2);
   dim3 numBlocks(numBlocksX, numBlocksY);
 
   // TIMINGS

  int width = 640, height = 480;
  double lowerX = -2, upperX = 2;
  double lowerY = -2, upperY = 2;
  int maxThreads = 1;
  char filename[100] = "fractal.png";
  bool quiet = false;


  if (rvalue != NULL)
    sscanf(rvalue, "%lf:%lf:%lf:%lf", &lowerX, &upperX, &lowerY, &upperY);
  if (tvalue != NULL)
    sscanf(tvalue, "%dx%d", &threadsX, &threadsY);
  if (filenameArg != NULL)
    sscanf(filenameArg, "%s", filename);

  if (!quiet) {
    printf("svalue = %s;%dx%d\nrvalue = %s; %lf, %lf, %lf, %lf\n", svalue, width, height, rvalue, lowerX, upperX, lowerY, upperY);
    printf("tvalue = %s; %dx%d\n", tvalue, threadsX, threadsY);
    printf("filenameArg = %s; %s\n", filenameArg, filename);
    printf("quiet = %d\n", quiet);
  }
  //////////////////////////////////

  Offset offset(lowerX, upperX, lowerY, upperY);
  generateImage(width, height, offset, threadsX, threadsY, filename, quiet);

  double iElaps = cpuSecondMonolitic() - iStart;
  // if (!quiet)
