Merge of Joan's Fitting framework in with the alignment refactor

This is just to track the integration between the two branches.