Rewriting onClose and onError as callbacks rather than filters