Changed analysis function to make it work with both constrained and unconstrained models