Add support for callbacks.

It's convoluted but it works.