Guard against undefined/null obj

Changes behaviour somewhat so I'd release as a major/minor rather than bugfix if you do accept. May be better to pass in an options object that checks for a `safe` option to allow the guard to be put in place or not, defaulting to not. Up to you.