I'd strongly recommend updating to 2019R2 given the significant improvements in the multiphase models.
Looking at the code, I'd also check whether f1 and f2 are giving sensible results: is the problem with the code not returning a number or the number returned is actually zero?