Issue #1010: $dp1 not defined

Turned out that the script aborts early on a few places if it can't find
the data it needs. Had a look and try to make the returns consistent
throghout the file.
Merge pull request #1201 from ditorelo/1010

Issue #1010: $dp1 not defined