Simplify the code a bit with std::unique_ptr.