Fixes #508

Callback might be undefined.
Merge pull request #511 from despairblue/patch-2

Fixes #508