 	if (HasBitmap())
 	{
 		CUDA_CHECK(cudaMalloc((void**) (&d_b), bitmapLength * sizeof(int)));
-		CUDA_CHECK(cudaMemcpyAsync(d_b, bitmap, packedLength * sizeof(int), cudaMemcpyHostToDevice, *stream));
+		CUDA_CHECK(cudaMemcpyAsync(d_b, bitmap, bitmapLength * sizeof(int), cudaMemcpyHostToDevice, *stream));
+		CUDA_CHECK(cudaStreamSynchronize(*stream));
 	}
-	
+
 	simple_packed_util::Unpack <<< gridSize, blockSize, 0, *stream >>> (d_p, d_u, d_b, coefficients, HasBitmap(), unpackedLength);
 
 	CUDA_CHECK(cudaFree(d_p));

		CUDA_CHECK(cudaStreamDestroy(*stream));
		delete stream;
	}
	
	return d_u;

}

		CUDA_CHECK(cudaStreamCreate(stream));
		destroyStream = true;
	}

	int blockSize = 512;
	int gridSize = unpackedLength / blockSize + (unpackedLength % blockSize == 0 ? 0 : 1);

