Added smart pointer to avoid leaks