Added logic to handle new tables vs existing tables scenarios.