Cleaned up, replace custom implementation with std::unique_ptr