Added smart pointer null checking