added fitting function