changed code to output table to a variable