Added new optimization parameter shallCancel, which is a function.