Fixed a bug in algorithm for determining neighbour cells.

Fixed a bug in algorithm for determining neighbour cells in class Grid.