After #25 is done, the exisiting code will be very slow with the rebuilding of the data set. Refactor the methods. The data set need only be built once, the formula needs to be updated on each cp or cn.
Likely need to split the generate_cp_formula_data call into two, one for the formula and one for the data.