Modified  to return nullptr if instance creation fails.