In any case which the Secretary sells a multifamily housing project acquired as the result of a default on a mortgage which was insured under this chapter to a cooperative which will operate it on a nonprofit basis and restrict permanent occupancy of its dwellings to members, or to a nonprofit corporation which operates as a consumer cooperative as defined by the Secretary, the Secretary may accept a purchase money mortgage, or upon application of the mortgagee, insure a mortgage under this section upon such terms and conditions as the Secretary determines are reasonable and appropriate, in a principal amount equal to the value of the property at the time of purchase, which value shall be based upon a mortgage amount on which the debt service can be met from the income of property when operated on a nonprofit basis after payment of all operating expenses, taxes, and required reserves; except that the Secretary may add to the mortgage amount an amount not greater than the amount of prepaid expenses and costs involved in achieving cooperative ownership, or make such other provisions for payment of such expenses and costs as the Secretary deems reasonable and appropriate. Prior to such disposition of a project, funds may be expended by the Secretary for necessary repairs and improvements.