Modify fitting function