added fitting function
removed unnecessary if statement