Refactor a few functions out of fit_discriminative