Split up fit function