close statement after checking if tables exist