move table.close() to finally block