created separate fitting function