Fixing livingNeighbors function to work with top and bottom