Complete restructure to use smart pointers.