On the rotation of cometary nuclei and small asteroids