Streamlined function num-neighbors a bit.