Some Rework to generalize fitting function