Clever (perhaps too clever) refactoring of the neighbor calculations