 	denominator = sx*sy*sz;
 	denominator *= denominator;
 
+	float W;
 	if (sqk != 0.0) {
 	    numerator = 12.5663706f/sqk;
 	    sum1 = 0.0;
 	    for (ix = -nbx; ix <= nbx; ix++) {
 		qx = unitkx*(kper+(float)(Nx*ix));
-		sx = exp(-.25f*pow(qx/kappa,2.0f));
+		sx = expf(-.25f*qx*qx/kappa2);
 		wx = 1.0f;
 		argx = 0.5f*qx*box.Lx/(float)Nx;
-		if (argx != 0.0) wx = pow(sin(argx)/argx,order);
+		if (argx != 0.0) wx = powf(sinf(argx)/argx,order);
 		for (iy = -nby; iy <= nby; iy++) {
 		    qy = unitky*(lper+(float)(Ny*iy));
-		    sy = exp(-.25f*pow(qy/kappa,2.0f));
+		    sy = expf(-.25f*qy*qy/kappa2);
 		    wy = 1.0f;
 		    argy = 0.5f*qy*box.Ly/(float)Ny;
-		    if (argy != 0.0) wy = pow(sin(argy)/argy,order);
+		    if (argy != 0.0) wy = powf(sinf(argy)/argy,order);
 		    for (iz = -nbz; iz <= nbz; iz++) {
 			qz = unitkz*(mper+(float)(Nz*iz));
-			sz = exp(-.25f*pow(qz/kappa,2.0f));
+			sz = expf(-.25f*qz*qz/kappa2);
 			wz = 1.0f;
 			argz = 0.5f*qz*box.Lz/(float)Nz;
-			if (argz != 0.0) wz = pow(sin(argz)/argz,order);
+			if (argz != 0.0) wz = powf(sinf(argz)/argz,order);
 
 			dot1 = unitkx*kper*qx + unitky*lper*qy + unitkz*mper*qz;
 			dot2 = qx*qx+qy*qy+qz*qz;
-			sum1 += (dot1/dot2) * sx*sy*sz * pow(wx*wy*wz,2.0f);
+			W = wx*wy*wz;
+			sum1 += (dot1/dot2) * sx*sy*sz * W*W;
 		    }
 		}
 	    }

	float numerator, denominator;

	mper = zn - Nz*(2*zn/Nz);
	snz = sin(0.5*unitkz*mper*box.Lz/Nz);
	snz2 = snz*snz;

	lper = yn - Ny*(2*yn/Ny);
	sny = sin(0.5*unitky*lper*box.Ly/Ny);
	sny2 = sny*sny;

	kper = xn - Nx*(2*xn/Nx);
	snx = sin(0.5*unitkx*kper*box.Lx/Nx);
	snx2 = snx*snx;
	sqk = pow(unitkx*kper,2.0f) + pow(unitky*lper,2.0f) +  pow(unitkz*mper,2.0f);


	int l;

    if(es_data.electrostatics_allocation_bool)
    {
	//kernel calling parameters for all grid dependent kernels
	int new_blocksize = 256;
	int new_gridsize = es_data.Nx*es_data.Ny*es_data.Nz / new_blocksize + 1;
      
	// setup the grid to run the kernel
	int blocksize = 256;
	dim3 grid( pdata.N / blocksize + 1, 1, 1);
	dim3 threads(blocksize, 1, 1);

