Fixes issue #534 avoids throwing error that undefined isnt a function

Noticed this as an intro bug which was left unfixed, patching this so that I can get started to the codebase. I'd be happy if this patch is reviewed.