Extracted adding to table to a function