Fix callback throwing error for `undefined` objects

This patches a problem where `undefined` is passed as a callback