Fix crasher: not checking for nil before invoking an ending handler.