             if (threadIdx.x == 0) {
 			    x_new = x;
 			    g_new.clear(); //dkoes - set gradient to zero
-                //TODO: unnecessary? are memset calls issued to the default stream?
-                cudaDeviceSynchronize();
             }
+            //TODO: unnecessary? are memset calls issued to the default stream?
+            __syncthreads();
+            cudaDeviceSynchronize();
 			return 0;
 		}
 		else if (f1 <= f0 + ALF * alpha * slope)


            //do we even care about the fast_line_search?
		    assert(params.type == minimization_params::BFGSAccurateLineSearch);
            cudaDeviceSynchronize();
        }
		alpha = accurate_line_search_gpu(f, n, x, g, f0,
                                                p, x_new, g_new, f1);
		if(alpha == 0) 

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