Added type check of callback parameter.

Not sure if this is necessary at both places, but I think the more you check the better. Thing for discussion: if to (1) through an error or (2) fail silently or (3) use a logger to report the error.