add support for onEnd callback