Fixed minor error.

The inner loop was not checking i,j,k correctly.
Fixed incorect indexing in build 3D problem.

I was not handling the z offset.
3D test