 	PrintReturnedMat(1, 1, tempCost);
 
 	printf("\nTotal cost is %f\n", cost);
-	*/
-
-		/* ----- Print grad vectort -----*/
-
-
-	//printf("\nTheta grad vector\n");
-	//printf("---------------------\n");
+
+*/
+
+	/* ------------------------------ */
+	/* ----- Print grad vectort ----- */
+	/* ------------------------------ */
+
+
+/*
+	printf("\nTheta grad vector\n");
+	printf("---------------------\n");
 
 	matGradVec = mxGetPr(plhs[1]);
 		
 	for (i = 0; i < thetaLength; i++) {
-//		printf("i = %d : %f\n", i+1, gradVec[i]);
+		printf("i = %d : %f\n", i+1, gradVec[i]);
+	}
+*/
+
+	
+	for (i = 0; i < thetaLength; i++) {
 		matGradVec[i] = gradVec[i];
 	}
-
 	
 
 	*matCost = cost;
-    	//matGradVec = gradVec;
+    //matGradVec = gradVec;
 	
 //	matGradVec = (double*)mxGetPr(plhs[1]);
 
+
+	/* --------------------------------- */
 	/* ----- Free allocated memory ----- */
+	/* --------------------------------- */
+
 	cublasDestroy(handle);
 	
 	cudaFree(W1); cudaFree(W2); cudaFree(b1); cudaFree(b2);

	cudaStat = cudaMemcpy(hostCost, tempCost, sizeof(double), 
						  cudaMemcpyDeviceToHost);

	cost = 1/(double)numberOfExamples * (*hostCost);



	/* ----- Compute gradients ----- */

	// Host matrices that will take the computed gradients
	double *hostDW1, *hostDW2, *hostDb1, *hostDb2;

	hostDW1 = (double*) malloc(hiddenSize*visibleSize*sizeof(double));

	}

	
	// Compute the final values of the weight gradients

	// Host matrices that will hold the final gradient values
	double *hostW1grad, *hostW2grad, *hostb1grad, *hostb2grad;

	hostW1grad = (double*) malloc(hiddenSize*visibleSize*sizeof(double));
	hostW2grad = (double*) malloc(visibleSize*hiddenSize*sizeof(double));
	hostb1grad = (double*) malloc(hiddenSize*sizeof(double));
