Adding plotting functions and attempting to make model fitting more stable.