Section 3. The department, in consultation with nonprofit organizations, the Community Economic Development Assistance Corporation established in chapter 40H, the Massachusetts Housing Finance Agency established in chapter 708 of the acts of 1966 and the Massachusetts Housing Partnership Fund established in section 35 of chapter 405 of the acts of 1985 shall identify those projects at greatest risk of prepayment or nonrenewal of rental assistance and shall grant preference in allocating funds pursuant to this chapter to those projects. The department shall enter into agreements to ensure that not less than 50 per cent of the units in such housing shall be occupied and affordable to persons of income of 80 per cent or less of the area median income and that not less than 10 per cent of such affordable units is available and affordable to households with income of 50 per cent or less of the area median income or such greater percentage of units as required by the Massachusetts Housing Finance Agency or the United States Department of Housing and Urban Development regulations. The department may enter into subcontracts with community development corporations, for-profit organizations or nonprofit organizations to carry out the purposes of the grants and loans and shall enter into contracts with the Community Economic Development Assistance Corporation, the Massachusetts Housing Finance agency and the Massachusetts Housing Partnership Fund. A portion of the funds may be allocated in the form of predevelopment grants or loans from the Community Economic Development Assistance Corporation and the Massachusetts Housing Partnership Fund to nonprofit purchasers of the housing. The housing shall remain affordable for not less than 40 years or for such longer period, based upon the useful life of the housing as determined by the department, as may be specified in the applicable recorded restriction at the registry of deeds or the registry district of the land court of the county in which the affected real property is located.