Fix for crash when passing undefined

Fix for crash in 2 places when inadvertently passing undefined.

Not sure if this is the best way to handle it...