changes to destructors to avoid segfaults on main exit