Properly delete states before exit