Move code to new countNeighbours() function