Implemented CountNeighbours method.