Check if callback exists and is a function before calling it

Fixes #1