This actually won't work since factory is null if ref is null.