working on the general purpose model fitting