working on fit function