 	printf("Finished.  nsamps=%d\n", nsamps_tot);
 	printf("Computing Sample mean...\n");
 	compute_sample_mean<<<N, 1>>>(samples, sample_mean, nsamps_tot, N);
-	compute_sample_covariance<<<N*(N+1)/2, 1>>>(samples, sample_covariance, nsamps_tot, N);
+	compute_sample_covariance<<<N, N>>>(samples, sample_covariance, nsamps_tot, N);
 	/*copy back sample  mean*/
 	cudaMemcpy(sample_mean_res, sample_mean, mean_size, cudaMemcpyDeviceToHost);
 	cudaMemcpy(samples_res, samples, samples_size, cudaMemcpyDeviceToHost);
-	cudaMemcpy(sample_covariance_res, sample_covariance, cov_size, cudaMemcpyDeviceToHost);
+	cudaMemcpy(sample_covariance_res, sample_covariance, full_cov_size, cudaMemcpyDeviceToHost);
 
 	/* Display*/
 	for(i=0; i<N; i++)

		printf("%f\n", sample_mean_res[i]);
	}
	write_paths_to_csv("maxent_samples.csv", samples_res, nsamps_tot, N, "w");
	write_paths_to_csv("maxent_cov.csv", sample_covariance_res, N*(N+1)/2, 1, "w");


	/* free memory */

	dim3 cov_block(N, N);

	cudaMalloc(&sample_mean, mean_size);
	cudaMalloc(&sample_covariance, full_cov_size);
	cudaMalloc(&samples, samples_size);
	cudaMalloc(&alpha, mean_size);
	cudaMalloc(&beta, cov_size);
