Use a smart pointer to avoid memory leak