Add check to avoid calling methods on undefined objects.  Prevents bugs
such as #174 and #266.
Merge pull request #280 from aodn/issue_274

Fix for bugs #174 and #266.