seperated out the grid generation code from the table command