Exhibit 10.40  SECOND AMENDMENT
TO
CREDIT AGREEMENT  THIS SECOND AMENDMENT dated as of May 2,
2006 (this Amendment), to the Credit Agreement, dated as of December 8,
2005, as amended by that certain First Amendment to Credit Agreement dated as
of January 11, 2006 (as so amended, the Credit Agreement), by and
among CLAYTON HOLDINGS, INC. a Delaware corporation (the Company), CITIGROUP
GLOBAL MARKETS REALTY CORP. (Citigroup) and BNP PARIBAS (BNP
Paribas), as administrative agent (in such capacity Administrative
Agent).  RECITALS  WHEREAS, subsection
2.1A(iv) of the Credit Agreement permits Lenders and/or other financial
institutions not a party to the Credit Agreement, that are approved by
Administrative Agent, to provide up to an aggregate amount of $10,000,000 in
additional Revolving Loan Commitments.  WHEREAS, Company
desires to exercise its right under subsection 2.1A(iv) of the Credit
Agreement to request additional Revolving Loan Commitments in an aggregate
principal amount of $5,000,000 (the Second Amendment Revolving Loan
Commitments).  WHEREAS, Citigroup has
agreed to make additional Revolving Loan Commitments in an aggregate principal
amount of $5,000,000 on the Second Amendment Effective Date (as defined below)
and Administrative Agent approves of the same.  WHEREAS, pursuant to
subsection 2.1A(iv) of the Credit Agreement, Company and Administrative
Agent are authorized to amend the Credit Agreement without the consent of the
Lenders to the extent necessary to give effect to such additional Revolving
Loan Commitments.  WHEREAS, pursuant to
an Assignment Agreement by and between Citigroup and BNP Paribas, and consented
to by Company and Administrative Agent (the Assignment), BNP Paribas
has, concurrently herewith, assigned to Citigroup (and Citigroup has assumed)
$2,000,000 of BNP Paribas Revolving Loan Commitment such that after giving
effect to this Amendment and the Assignment, the aggregate Revolving Loan
Commitment of Citigroup will be $7,000,000.  NOW THEREFORE, in
consideration of the foregoing premises and other good and valuable
consideration, the parties hereto hereby agree as follows:  1.             Definitions. 
Any capitalized term used herein and not defined herein shall have the
meaning assigned to it in the Credit Agreement.   1


2.             Amendments
to Definitions.  (a)           New definitions of Second
Amendment and Second Amendment Revolving Loan Commitments shall be added to Section 1.1
in alphabetical order reading as follows:  Second Amendment
means that certain Second Amendment to this Agreement dated as of May 2,
2006.  Second Amendment Effective
Date means the date the Second Amendment becomes effective in
accordance with its terms.  Second Amendment Revolving
Loan Commitments means the additional Revolving Loan Commitments
provided pursuant to the Second Amendment.  3.             Amendments
to Section 2: Amounts and Terms of Commitments and Loans.  (a)           First paragraph of
subsection 2.1A(ii) of the Credit Agreement is hereby amended by deleting
such subsection in its entirety and substituting the following therefor:  (A)Revolving Loans.  Each Revolving Lender severally agrees,
subject to the limitations set forth below with respect to the maximum amount
of Revolving Loans permitted to be outstanding from time to time, to lend to
Company from time to time during the period from the Closing Date to but
excluding the Revolving Loan Commitment Termination Date an aggregate amount
not exceeding its Pro Rata Share of the aggregate amount of the Revolving Loan
Commitments to be used for the purposes identified in subsection 2.5B.  As of the Second Amendment Effective Date,
the amount of each Revolving Lenders Revolving Loan Commitment is set forth
opposite its name on Schedule 2.1 annexed hereto and the aggregate
Revolving Loan Commitment Amount is $50,000,000 (consisting of Revolving Loan
Commitments in the aggregate amount of $40,000,000 as of the Closing Date plus
First Amendment Revolving Loan Commitments in the aggregate amount of $5,000,000
plus Second Amendment Revolving Loan Commitments in the aggregate amount of
$5,000,000); provided that the amount of the Revolving Loan Commitment of
each Revolving Lender shall be adjusted to give effect to any assignment of
such Revolving Loan Commitment pursuant to subsection 10.1B and shall be
reduced from time to time by the amount of any reductions thereto made pursuant
to subsection 2.4 and increased from time to time by the amount of any
increases thereto made pursuant to subsection 2.1(iv).  Each Revolving Lenders Revolving Loan
Commitment shall expire on the Revolving Loan Commitment Termination Date and
all Revolving Loans and all other amounts owed hereunder with respect to the
Revolving Loans and the Revolving Loan Commitments shall be paid in full no
later than that date.  Amounts borrowed
under this subsection 2.1A(ii) may   2


be repaid and reborrowed to but excluding the Revolving Loan Commitment
Termination Date.  (b)           Company acknowledges
that, after giving effect to the Second Amendment Revolving Loan Commitments,
Company will have no further capacity to add Revolving Loan Commitments under
subsection 2.1A(iv).  4.             Amendment to Schedule 2.1.  Schedule 2.1 of the Credit Agreement is
hereby amended by increasing Citigroups Revolving Loan Commitment by
$7,000,000 and reducing BNP Paribas Revolving Loan Commitment by $2,000,000.  5.             Conditions to Effectiveness.  The effectiveness of this Amendment is
subject to the fulfillment of each of the following conditions precedent (the
date such conditions are fulfilled is hereafter referred to as the Second
Amendment Effective Date):  (a)           After giving effect
to this Amendment, no Event of Default or Potential Event of Default shall have
occurred and be continuing on the Second Amendment Effective Date or result
from this Amendment becoming effective in accordance with its terms and Company
shall have delivered an Officers Certificate to such effect.  (b)           Administrative Agent
shall have executed this Amendment and received a counterpart of this Amendment
that bears the signature of Citigroup, the Company and each of the Guarantors.  (c)           All corporate and
other proceedings taken or to be taken in connection with the transactions
contemplated hereby and all documents incidental thereto not previously found
acceptable by Administrative Agent, acting on behalf of Lenders, and its
counsel shall be satisfactory in form and substance to Administrative Agent and
such counsel, and Administrative Agent and such counsel shall have received all
such counterpart originals or certified copies of such documents as
Administrative Agent may reasonably request.  (d)           Administrative Agent
shall be satisfied that all requirements of subsection 2.1A(iv) of the
Credit Agreement shall have been met.  (e)           Delivery by Citigroup,
Company, BNP Paribas and Administrative Agent of the Assignment, together with
such other documentation and fees required by subsection 10.1 of the Credit
Agreement for the effectiveness of the Assignment pursuant to the Credit
Agreement.  6.             Expenses. 
Without limiting any obligation of the Company to reimburse the expenses
pursuant to the terms of the Loan Documents, the Company hereby agrees that on
or before the Second Amendment Effective Date, the Company shall reimburse the
Administrative Agent for any and all out of pocket expenses (including
reasonable attorneys fees) incurred by the Administrative Agent in connection
with this Amendment and the matters related hereto.   3


7.             Representations and Warranties.  The Company hereby represents and warrants to
the Lenders as follows:  (a)           Immediately prior
to, or after giving effect to this Amendment, no Event of Default or Potential
Event of Default has occurred and is continuing or would result from this
Amendment becoming effective in accordance with its terms.  (b)           The execution,
delivery, and performance by each of the Company and the Guarantors of this
Amendment have been duly authorized by all necessary action on the part of such
Person.  (c)           The execution,
delivery and performance by Company and the Guarantors of this Amendment and
the consummation of the transactions contemplated hereby do not and will not (i) violate
any provision of any law or any governmental rule or regulation applicable
to Company or any of their Subsidiaries, the Organizational Documents of
Company or any of their Subsidiaries or any order, judgment or decree of any
court or other Government Authority binding on Company or any of their
Subsidiaries, (ii) conflict with, result in a breach of or constitute
(with due notice or lapse of time or both) a default under any Contractual
Obligation of Company or any of its Subsidiaries, (iii) result in or
require the creation or imposition of any Lien upon any of the properties or
assets of Company or any of its Subsidiaries (other than any Liens created
under any of the Loan Documents in favor of Administrative Agent on behalf of
Lenders), or (iv) require any approval of stockholders or any approval or
consent of any Person under any Contractual Obligation of Company or any of its
Subsidiaries, except for such approvals or consents which will be obtained on
or before the Second Amendment Effective Date and disclosed in writing to
Lenders and except, in each case, to the extent such violation, conflict, Lien
or failure to obtain such approval or consent would not reasonably be expected
to result in a Material Adverse Effect.  (d)           This Amendment is
the legally valid and binding obligations of each of the Company and the
Guarantors, enforceable against such Person in accordance with its terms,
except as enforcement may be limited by equitable principles or by bankruptcy,
insolvency, reorganization, moratorium, or similar laws relating to or limiting
creditors rights generally.  8.             Miscellaneous.  (a)           Except as otherwise
expressly provided herein, each of the Company and the Guarantors hereby agree
that (i) the Credit Agreement and the other Loan Documents are, and shall
continue to be, in full force and effect and are hereby ratified and confirmed
in all respects, except that on and after the Second Amendment Effective Date (A) all
references in the Credit Agreement to this Agreement, hereto, hereof, hereunder
or words of like import referring to the Credit Agreement shall mean the Credit
Agreement as amended by this Amendment and (B) all references in the other
Loan Documents to the Credit Agreement, thereto, thereof, thereunder or
words of like import referring to the Credit Agreement shall mean the Credit
Agreement as amended by this Amendment, (ii) to the extent that the Credit
Agreement or any other   4


Loan
Document purports to pledge to the Administrative Agent, or to grant to the
Administrative Agent a security interest in or lien on, any collateral as
security for the Obligations, such pledge or grant of a security interest or
lien is hereby ratified and confirmed in all respects, and (iii) the
execution, delivery and effectiveness of this Amendment shall not operate as an
amendment of any right, power or remedy of the Administrative Agent or the
Lenders under the Credit Agreement or any other Loan Document, nor constitute
an amendment of any provision of the Credit Agreement or any other Loan
Document.  (b)           Company hereby
acknowledges and agrees that this Amendment constitutes a Loan Document under
the Credit Agreement.  Accordingly, it
shall be an Event of Default under the Credit Agreement if any representation
or warranty made by the Company under or in connection with this Amendment
shall have been untrue, false or misleading in any material respect when made.  (c)           This Amendment may
be executed in any number of counterparts and by different parties hereto in
separate counterparts, each of which shall be deemed to be an original, but all
of which taken together shall constitute one and the same agreement.  Delivery of an executed counterpart of this
Amendment by telefacsimile or electronic mail shall be equally as effective as
delivery of an original executed counterpart of this Amendment.  (d)           Section headings
herein are included for convenience of reference only and shall not constitute
a part of this Amendment for any other purpose.  9.             Acknowledgement and Consent by Guarantors.  Each guarantor listed on the signature pages hereof
(Guarantors) hereby acknowledges that it has read this Amendment and
consents to the terms thereof, and hereby confirms and agrees that, after the
effectiveness of this Amendment, the obligations of each Guarantor under its
applicable Guaranty shall not be impaired, excused or diminished and the
applicable Guaranty is, and shall continue to be, in full force and effect and
is hereby confirmed and ratified in all respects, and that the Guaranteed
Obligations shall include all Obligations under the Credit Agreement as amended
by this Amendment.  Each Guarantor
further agrees that nothing in the Credit Agreement, this Agreement or any
other Loan Document shall be deemed to require the consent of such Guarantor to
any future amendment to the Credit Agreement.  10.           Governing Law. 
THIS AMENDMENT AND THE RIGHTS AND OBLIGATIONS OF THE PARTIES HEREUNDER
SHALL BE GOVERNED BY, AND SHALL BE CONSTRUED AND ENFORCED IN ACCORDANCE WITH,
THE INTERNAL LAWS OF THE STATE OF NEW YORK (INCLUDING WITHOUT LIMITATION SECTION 5-1401
OF THE GENERAL OBLIGATIONS LAW OF THE STATE OF NEW YORK).   5


IN WITNESS WHEREOF, the
parties hereto have caused this Amendment to be executed and delivered as of
the date first above written.  COMPANY:CLAYTON HOLDINGS, INC.By:
  /s/
  Frederick C. HerbstName:
  Frederick C. HerbstTitle:
  Chief Financial
  OfficerGUARANTORS:GRP HOLDINGS, INC.By:
  /s/
  Frederick C. HerbstName:
  Frederick C. HerbstTitle:
  TreasurerCLAYTON SERVICES, INC.By:
  /s/
  Frederick C. HerbstName:
  Frederick C. HerbstTitle:
  Chief
  Financial OfficerCLAYTON TECHNOLOGIES, INC.By:
  /s/
  Frederick C. HerbstName:
  Frederick C. HerbstTitle:
  Chief
  Financial OfficerFIRST MADISON SERVICES, INC.By:
  /s/
  Frederick C. HerbstName:
  Frederick C. HerbstTitle:
  Chief
  Financial Officer   S-1


AG NI HOLDINGS, INC.By:
  /s/
  Frederick C. HerbstName:
  Frederick C. HerbstTitle:
  Chief
  Financial OfficerQUANTUM SERVICING CORPORATIONBy:
  /s/ Steve
  CohenName
  : Steve CohenTitle:
  Vice
  President and SecretaryTMHC HOLDINGS, INC.By:
  /s/ Kevin
  J. KanouffName:
  Kevin J. KanouffTitle:
  PresidentCLAYTON FIXED INCOME SERVICES
  INC.By:
  /s/ Kevin
  J. KanouffName:
  Kevin J. KanouffTitle:
  PresidentCLAYTON IPS CORPORATIONBy:
  /s/ Kevin
  J. KanouffName:
  Kevin J. KanouffTitle:
  Chief
  Executive Officer   S-2


ADMINISTRATIVE AGENT:BNP PARIBASBy:
  /s/ Amy KirschnerName:
  Amy
  KirschnerTitle:
  DirectorBy:
  /s/ Dimitri JobertName:
  Dimitri
  JobertTitle:
  Director   S-3


LENDERS:CITIGROUP
  GLOBAL MARKETS REALTY CORP.By:Name:Title:Notice
  Address390
  Greenwich Street, 6th FloorNew
  York, NY 10013Attn:
  Kyle C. Sligar(212)
  723-5486kyle.sligar@citigroup.com   S-4