added fitting code