adapting code to use smart pointers