Fixed foreach loop for adding tables and columns