Factorise table creation code

And fix comments.