Factor out list-walking.