table: Factor out common code and improve comments.