Change loops to derive the number of tables automatically