stencil optimization working