 	printf("Copying postings from host to device\n");
 
   // POSTINGS TO DEVICE
-	checkCuda( cudaMalloc((void**)&d_postings, sizeof(Posting) * terms) );
-	checkCuda( cudaMemcpy(d_postings, postingsLoaded, sizeof(Posting) * terms, cudaMemcpyHostToDevice) );
+	checkCuda( cudaMalloc((void**)&dev_postings, sizeof(Posting) * terms) );
+	checkCuda( cudaMemcpy(dev_postings, postingsLoaded, sizeof(Posting) * terms, cudaMemcpyHostToDevice) );
 	int i;
-	int *d_docIds;
-	float *d_weights;
+	int *dev_docIds;
+	float *dev_weights;
 	for (i = 0; i < terms; i++) {
 		Posting p = postingsLoaded[i];
 
-		checkCuda( cudaMalloc((void**) &d_docIds, sizeof(int) * p.docsLength) );
-		checkCuda( cudaMalloc((void**) &d_weights, sizeof(float) * p.docsLength) );
-
-		checkCuda( cudaMemcpy(&(d_postings[i].docIds), &(d_docIds), sizeof(int *), cudaMemcpyHostToDevice) );
-		checkCuda( cudaMemcpy(&(d_postings[i].weights), &(d_weights), sizeof(float *), cudaMemcpyHostToDevice) );
-
-		checkCuda( cudaMemcpy(d_docIds, p.docIds, sizeof(int) * p.docsLength, cudaMemcpyHostToDevice) );
-		checkCuda( cudaMemcpy(d_weights, p.weights, sizeof(float) * p.docsLength, cudaMemcpyHostToDevice) );
+		checkCuda( cudaMalloc((void**) &dev_docIds, sizeof(int) * p.docsLength) );
+		checkCuda( cudaMalloc((void**) &dev_weights, sizeof(float) * p.docsLength) );
+
+		checkCuda( cudaMemcpy(&(dev_postings[i].docIds), &(dev_docIds), sizeof(int *), cudaMemcpyHostToDevice) );
+		checkCuda( cudaMemcpy(&(dev_postings[i].weights), &(dev_weights), sizeof(float *), cudaMemcpyHostToDevice) );
+
+		checkCuda( cudaMemcpy(dev_docIds, p.docIds, sizeof(int) * p.docsLength, cudaMemcpyHostToDevice) );
+		checkCuda( cudaMemcpy(dev_weights, p.weights, sizeof(float) * p.docsLength, cudaMemcpyHostToDevice) );
 
 	}
 

    termPos++;
  }

  int *d_queryTerms;
	float *docScores, *d_docScores;
	int BLOCK_SIZE = 1024;
	int numBlocks = (docs + BLOCK_SIZE - 1) / BLOCK_SIZE;

	docScores = (float *) malloc(sizeof(float) * docs);
	cudaMalloc((void **) &d_queryTerms, querySize * sizeof(int));
  cudaMalloc((void **) &d_docScores, docs * sizeof(float));

  cudaMemcpy(d_queryTerms, queryTerms, querySize * sizeof(int), cudaMemcpyHostToDevice);

	cudaEventRecord(resolveQueryStart);
	k_resolveQuery<<<numBlocks, BLOCK_SIZE>>>(
		d_postings,
		dev_docsNorm,
		terms,
		docs,
		d_queryTerms,
		querySize,
		d_docScores
	);
	handleKernelError();
	cudaEventRecord(resolveQueryStop);

	cudaMemcpy(docScores, d_docScores, docs * sizeof(float), cudaMemcpyDeviceToHost);

	cudaEventSynchronize(resolveQueryStop);
	float milliseconds = 0;

		printf("doc %d: %4.2f\n", i, docScores[i]);
	}

	cudaFree(dev_queryTerms);
	cudaFree(dev_docScores);
  free(queryTerms);
}

