             if (cur_adj < n_stencil)
                 {
                 // compute the stenciled cell cartesian coordinates
-                Scalar4 stencil = d_stencil[stencil_idx(cur_adj, my_type)];
+                Scalar4 stencil = texFetchScalar4(d_stencil, stencil_1d_tex, stencil_idx(cur_adj, my_type));
                 int sib = ib + __scalar_as_int(stencil.x);
                 int sjb = jb + __scalar_as_int(stencil.y);
                 int skb = kb + __scalar_as_int(stencil.z);
                 cell_dist2 = stencil.w;
 
                 // wrap through the boundary
-                bool in_bounds = true;
-                if (periodic.x)
-                    {
-                    if (sib >= (int)ci.getW()) sib -= ci.getW();
-                    if (sib < 0) sib += ci.getW();
-                    }
-                else if (sib < 0 || sib >= (int)ci.getW())
-                    {
-                    // in aperiodic systems the stencil could maybe extend out of the grid
-                    in_bounds = false;
-                    }
-
-                if (periodic.y)
-                    {
-                    if (sjb >= (int)ci.getH()) sjb -= ci.getH();
-                    if (sjb < 0) sjb += ci.getH();
-                    }
-                else if (sjb < 0 || sjb >= (int)ci.getH())
-                    {
-                    in_bounds = false;
-                    }
-
-                if (periodic.z)
-                    {
-                    if (skb >= (int)ci.getD()) skb -= ci.getD();
-                    if (skb < 0) skb += ci.getD();
-                    }
-                else if (skb < 0 || skb >= (int)ci.getD())
-                    {
-                    in_bounds = false;
-                    }
-
-                if (in_bounds)
-                    {
-                    neigh_cell = ci(sib, sjb, skb);
-                    neigh_size = d_cell_size[neigh_cell];
-                    }
-                else
-                    {
-                    neigh_cell = 0;
-                    neigh_size = 0;
-                    }
+                if (sib >= (int)ci.getW() && periodic.x) sib -= ci.getW();
+                if (sib < 0 && periodic.x) sib += ci.getW();
+                if (sjb >= (int)ci.getH() && periodic.y) sjb -= ci.getH();
+                if (sjb < 0 && periodic.y) sjb += ci.getH();
+                if (skb >= (int)ci.getD() && periodic.z) skb -= ci.getD();
+                if (skb < 0 && periodic.z) skb += ci.getD();
+
+                neigh_cell = ci(sib, sjb, skb);
+                neigh_size = d_cell_size[neigh_cell];
                 }
             else
                 // we are past the end of the cell neighbors

    return max_threads;
    }

void gpu_nlist_multi_binned_bind_texture(const Scalar4 *d_cell_xyzf, unsigned int n_elements)
    {
    // bind the position texture
    cell_xyzf_1d_tex.normalized = false;
    cell_xyzf_1d_tex.filterMode = cudaFilterModePoint;
    cudaBindTexture(0, cell_xyzf_1d_tex, d_cell_xyzf, sizeof(Scalar4)*n_elements);
    }

//! recursive template to launch neighborlist with given template parameters

                    has_neighbor = 1;
                    }

                } while (0); // particle is processed exactly once

            // advance cur_offset
            cur_offset += threads_per_particle;
