Add check for existence of object before deref.

This was relevant at some stage, sorry I can't remember what the
actual issue was, but in any case it is always safe to check an
object for non-falsy value before dereferencing it.