updated ml_formula function