Added nullptr shecks to object.factory()

Trying to fix #275