precompute neighbors into matrix for performance