         if (threadIdx.x == 0) {
 		    x_new = x;
 		    g_new.clear(); //dkoes - set gradient to zero
-            cudaDeviceSynchronize();
         }
+        __syncthreads();
+        cudaDeviceSynchronize();
 		return 0;
 	}
     if (threadIdx.x == 0) {

    }
	for (;;) //always try full newton step first
	{
        if (threadIdx.x == 0) {
		    x_new = x;
            cudaDeviceSynchronize();
		    x_new.increment(p, alpha);
            cudaDeviceSynchronize();
        }

        //TODO: remove temp variable
		fl ftemp = f(x_new, g_new);

		    y = g_new;
            // Update line direction
		    subtract_change(y, g, n);

		    prevf0 = f0;
		    f0 = f1;
		    x = x_new;
        }
        __syncthreads();
        cudaDeviceSynchronize();

		if (params.early_term)
		{
