Reduce count_neighbours code using product