
181 Cal.App.3d 122 (1986)
226 Cal. Rptr. 321
MARINA TENANTS ASSOCIATION et al., Plaintiffs and Appellants,
v.
DEAUVILLE MARINA DEVELOPMENT CO., LTD., et al., Defendants and Appellants.
Docket No. B009329.
Court of Appeals of California, Second District, Division Three.
May 19, 1986.
*125 COUNSEL
Alvin F. Howard, Ronald L. Rouda and Robert M. Hodes for Plaintiffs and Appellants.
Miller & Chernoff, Stanley M. Chernoff, Howard, Ring & Chizever, Ralph M. Weiss, Hillel Chodos, Rafael Chodos, Gina Marie Putkoski, Alschuler, Grossman & Pines, Bruce Warner and Michael L. Cypers for Defendants and Appellants.
[Opinion certified for partial publication.[]]
*126 OPINION
KLEIN, P.J.
Plaintiffs, appellants and cross-respondents Marina Tenants Association et al. (Tenants), appeal from an order of dismissal following the sustaining of demurrers without leave to amend interposed by defendants, respondents and cross-appellants Deauville Marina Development Co., Ltd., a limited partnership (Deauville), Marina Admiralty Co., a limited partnership (Marina Admiralty), Bar Harbor Development Co., Ltd., a limited partnership (Bar Harbor), and Marina del Rey Country Club Apartments, a partnership doing business as Oakwood Garden Apartments (Oakwood), collectively referred to as Lessees.
The Lessees cross-appeal from an order striking various items from their memoranda of costs and disbursements.
The Tenants cannot state a cause of action as third party beneficiaries, because even if they succeed in proving they are intended beneficiaries of the lease agreement (master lease) between the County of Los Angeles (the County) and the Lessees, they cannot assert rights greater than those of the promisee, herein the County, under that contract.

FACTUAL AND PROCEDURAL BACKGROUND
The Lessees leased publicly owned land in Marina del Rey from the County, and constructed apartment buildings, commercial structures, and other improvements. The Tenants are persons who rent premises from the Lessees.
On June 9, 1983, the Tenants as a class filed a third amended complaint, the gravamen of which was that the Tenants were third-party beneficiaries of the standard form master leases between the County and the Lessees.
The complaint set forth, inter alia: "4. Each and all of the lease agreements by and between the County ... and each of the Lessees provide, among other things, that: [¶] A. The Lessee will, at its own cost and expense, construct and provide certain facilities on the premises demised to the Lessee and put such facilities to public use. The method of putting said facilities to public use includes the rental of said facilities to Tenants. [¶] B. The rental rates to be charged to Tenants shall be fair and reasonable based upon the following two considerations: [¶] (1) The demised property is intended to serve a public use and to provide needed facilities to the public at fair and reasonable cost, and [¶] (2) Lessee is entitled to a fair and reasonable return upon Lessee's investment pursuant to the lease."
*127 The complaint alleged "[t]he aforesaid provisions of the lease agreements alleged in paragraph 4 hereof were intended for the benefit of the Tenants[,]" and that the Lessees charged, and Tenants paid, rents at rates higher than what is "fair and reasonable."
The Tenants prayed for damages equal to the amount of any excess rents actually paid.
The trial court sustained the Lessees' demurrers without leave to amend and dismissed the action, ruling the Tenants are only incidental beneficiaries and without standing to bring the action.

CONTENTIONS
The Tenants contend the causes of action based upon third-party beneficiary to contract and unjust enrichment are adequately pled.
The Lessees counter that the Tenants are merely incidental beneficiaries of the master lease, and the cause of action based upon unjust enrichment is purely derivative of the Tenants' third-party beneficiary theory and must in turn fail, among other contentions.
On cross-appeal, the Lessees claim their reasonable attorney's fees and costs should have been allowed.

DISCUSSION

1. Scope of appellate review.

(1) The allegations in the complaint must be regarded as true (Shaeffer v. State of California (1970) 3 Cal. App.3d 348, 354 [83 Cal. Rptr. 347]), and are to be liberally construed with a view to substantial justice between the parties. (King v. Central Bank (1977) 18 Cal.3d 840, 843 [135 Cal. Rptr. 771, 558 P.2d 857].) Unless the complaint shows on its face that it is incapable of amendment, denial of leave will constitute an abuse of discretion. (King v. Mortimer (1948) 83 Cal. App.2d 153, 158 [188 P.2d 502].)
(2) The function of a demurrer is to test the sufficiency of a plaintiff's pleading by raising questions of law. (Buford v. State of California (1980) 104 Cal. App.3d 811, 818 [164 Cal. Rptr. 264].) (3) "As a reviewing court we are not bound by the construction placed by the trial court on the pleadings but must make our own independent judgment thereon, even as to matters not expressly ruled upon by the trial court." (Miller v. Bakersfield *128 News-Bulletin, Inc. (1975) 44 Cal. App.3d 899, 901 [119 Cal. Rptr. 92].)
Other relevant matters which are properly the subject of judicial notice (Evid. Code, § 452) may be treated as having been pled. (Helix Land Co. v. City of San Diego (1978) 82 Cal. App.3d 932, 937 [147 Cal. Rptr. 683].)[1]
(4) Finally, where an ambiguous contract is the basis of an action, it is proper, if not essential, for a plaintiff to allege its own construction of the agreement. So long as the pleading does not place a clearly erroneous construction upon the provisions of the contract, in passing upon the sufficiency of the complaint, we must accept as correct plaintiff's allegations as to the meaning of the agreement. (Pigeon Point Ranch, Inc. v. Perot (1963) 59 Cal.2d 227, 233 [28 Cal. Rptr. 865, 379 P.2d 321].)
We apply these principles in reviewing the complaint.

2. General principles re third-party beneficiaries.

The rule relating to third party beneficiary contracts is codified in Civil Code section 1559 (section 1559), as follows: "A contract, made expressly for the benefit of a third person, may be enforced ... at any time before the parties thereto rescind it." (5) The section excludes enforcement of a contract by persons who are only incidentally or remotely benefited by it. (Lucas v. Hamm (1961) 56 Cal.2d 583, 590 [15 Cal. Rptr. 821, 364 P.2d 685].)
However, it is not necessary that the contract identify or refer to the third party by name; it is sufficient if it can be shown that the claimant is of a class of persons for whose benefit it was made. (Johnson v. Holmes Tuttle Lincoln-Merc. (1958) 160 Cal. App.2d 290, 297 [325 P.2d 193]; 1 Witkin, Summary of Cal. Law (8th ed. 1973) Contracts, § 507, p. 435.) "Insofar as intent to benefit a third person is important in determining [the] right to bring an action under a contract, it is sufficient that the promisor must have understood that the promisee had such intent." (Lucas v. Hamm, supra, at p. 591.) Further, no specific manifestation by the promisor of an intent to benefit the third person is required. (Ibid.)
In so holding, our Supreme Court disapproved earlier cases to the extent they required "that to permit a third person to bring an action on a contract *129 there must be `an intent clearly manifested by the promisor' to secure some benefit to the third person." (Ibid.)

a. Where governmental entity is a party.

While section 1559 clearly allows third-party suits for breaches of contract where no government agency is a party to the contract, whether such suits are allowed when the government contracts with a private party depends upon analysis of the decisions in Martinez v. Socoma Companies, Inc. (1974) 11 Cal.3d 394 [113 Cal. Rptr. 585, 521 P.2d 841] and Zigas v. Superior Court (1981) 120 Cal. App.3d 827 [174 Cal. Rptr. 806].
In Martinez, plaintiffs sought to enforce the terms of a contract between defendant manufacturers and the United States government. Under the agreement, defendants received federal funds with which they were to hire and train the "hard-core unemployed" of East Los Angeles. When defendants failed to perform, plaintiffs, who were allegedly East Los Angeles residents certified as disadvantaged and eligible for employment under the program, sought to recover under the contract.
The Martinez court held standing to sue as a third-party beneficiary to a government contract depends on the intent of the parties as manifested by the terms of the contract, and the circumstances surrounding the formation of the agreement, and on that basis found the plaintiffs were incidental beneficiaries, and therefore without such standing. (Martinez v. Socoma Companies, Inc., supra, 11 Cal.3d at pp. 401-402.)
In Zigas, plaintiff tenants alleged they were third-party beneficiaries of a contract between landlords of apartments financed by federally insured mortgages and the Department of Housing and Urban Development (HUD). Under said contract, landlords were obligated not to charge more than the HUD-approved rent schedule. Applying the principles of Martinez, the Zigas court determined the tenants were intended, and not incidental beneficiaries, and therefore had standing to sue. (Zigas v. Superior Court, supra, 120 Cal. App.3d at p. 837.)
In reaching its holding, the Zigas court distinguished its fact situation from that of Martinez, and set forth the various factors upon which its decision was based as follows: (1) in Martinez, the federal government was "out of pocket" as a consequence of the breach, while in Zigas, the tenants suffered the direct pecuniary loss; (2) in Martinez, the agreement provided governmental administrative procedures for the resolution of disputes arising out of contract, but no such procedures were available in Zigas; (3) in *130 Martinez, a liquidated damages provision indicated defendants bargained for limited liability, while in Zigas, the court found no basis for limited liability; (4) in Martinez, "the contracts ... were designed not to benefit individuals as such but to ... improv[e] the East Los Angeles neighborhood" (Martinez v. Socoma Companies, Inc., supra, 11 Cal.3d at p. 406), whereas in Zigas, the purpose was a narrow one, namely, to provide moderate rental housing for families with children; (5) finally, in Zigas, the provision in the contract to charge rents consistent with the HUD schedule manifested an intent to make tenants direct, not incidental, beneficiaries of the agreement. (Zigas v. Superior Court, supra, 120 Cal. App.3d at pp. 837-838.)

3. Contrary to the trial court's ruling that the public is the sole intended beneficiary of the master lease, it is susceptible to the interpretation that Tenants are also intended beneficiaries thereof.

The Tenants alleged in their third amended complaint that the rents charged the Tenants were to be "fair and reasonable" under the master lease and that said provision was intended for their benefit. In so pleading, the Tenants relied on selected portions of the master lease.
(6) "`The rule is well settled that a complaint otherwise good on its face is nevertheless subject to demurrer when facts judicially noticed render it defective....: "The theory is that the pleader should not be allowed to bypass a demurrer by suppressing facts which the court will judicially notice."'" (Legg v. Mutual Benefit Health & Accident Assn. (1960) 184 Cal. App.2d 482, 488 [7 Cal. Rptr. 595].) It was therefore proper here for the trial court to judicially notice the master lease in its entirety.
Paragraph 4 of said master lease (paragraph 4) provides: "ACTIVE PUBLIC USE. [¶] The ultimate object of this lease is the complete and continuous use of the premises herein demised by and for the benefit of the public, without discrimination as to race or religion, the immediate object being the development and realization of the greatest possible revenue therefrom. It is agreed that said immediate and ultimate objects are consistent and compatible. Accordingly, Lessee covenants and agrees that he will operate said premises fully and continuously to the end that the public may enjoy maximum benefits and County may obtain maximum revenue therefrom. [¶] In the event of any dispute or controversy relating hereto, this lease shall be construed with due regard to the aforesaid objects." (Italics added.)
After setting forth that prices are to be fair and reasonable, paragraph 16 of the lease (paragraph 16), provides in the event the Director of the Department of Small Craft Harbors of the County of Los Angeles (Director) *131 "notifies Lessee that any of said prices are not fair and reasonable, Lessee shall have the right to confer with Director and to justify said prices. If, after reasonable conference and consultation, Director shall determine that any of said prices are not fair and reasonable, the same shall be modified by Lessee, ..., as directed. [¶] The Lessee may appeal the determination of the Director to the Board of Supervisors, whose decision shall be final and conclusive. Pending such appeal, the prices fixed by the Director, shall be the maximum charged by the Lessee."
After also considering these paragraphs of the lease, the trial court herein held "Martinez determined that the intent surrounding the execution of the agreement can be determined from the agreement. The intent specifically set forth in this lease is to benefit the public. The tenants are only incidental beneficiaries and do not have standing as third party beneficiaries to bring this action."

a. Paragraphs in the master lease appear in internal conflict.

(7) The interpretation of a written instrument is solely a judicial function to be exercised according to the generally accepted canons of interpretation, unless the interpretation turns upon the credibility of extrinsic evidence. (Parsons v. Bristol Development Co. (1965) 62 Cal.2d 861, 865 [44 Cal. Rptr. 767, 402 P.2d 839].) There being no issue of credibility here, we interpret the master lease anew.
(8) In so doing, we apply the rule of Martinez that status as a third-party beneficiary depends upon the intent of the parties as manifested by the terms of the contract and the circumstances surrounding the formation of the agreement. (Martinez v. Socoma Companies, Inc., supra, 11 Cal.3d at pp. 401-402.)
Paragraph 4 articulates the ultimate and immediate objectives of the lease as being to benefit the public and to maximize revenue to the County, respectively; paragraph 16 controls "prices charged for all goods or services, ..., supplied to the public on or from the premises ... demised, ..."
In Zigas v. Superior Court, supra, 120 Cal. App.3d at page 835, dealing with an analogous fact situation, the court observed "it is clear that a requirement of HUD approval of rent increases could only benefit the tenants." Here, notwithstanding the pronouncements of paragraph 4, to the extent paragraph 16 controls the level of rents, only the Tenants could benefit thereby; it cannot be seriously maintained that the general public, including County residents living elsewhere, are somehow benefited. To the contrary, *132 such residents are interested in the County's receiving maximum revenues, thus lessening individual tax burdens. Consequently, there appears to be some tension between the various purposes emerging from the lease. Language in paragraph 4 that "in the event of any dispute ... [the] lease shall be construed with due regard to the aforesaid objects[,]" (italics added) does not negate that at least in part, the lease appears to have been designed to benefit the Tenants.
(9) We treat the master lease as having been pled in its entirety. (Helix Land Co. v. City of San Diego, supra, 82 Cal. App.3d at p. 937.) Because the lease is ambiguous as to whether the Tenants are intended beneficiaries, it was proper for the Tenants to allege their construction of said agreement. (Pigeon Point Ranch, Inc. v. Perot, supra, 59 Cal.2d at p. 233.) The complaint did not place a clearly erroneous construction upon the terms of the lease. Therefore, in reviewing its sufficiency, the Tenants' allegations as to the parties' intent must be accepted as correct. (Ibid.)

4. Irrespective of ambiguities, the Tenants, as alleged intended third parties beneficiaries, cannot assert rights greater than those of the County.

(10) However, even if the Tenants succeed in proving they are intended beneficiaries of the rent restrictions in the master lease, they cannot obtain the sought after relief.
A third-party beneficiary cannot assert greater rights than those of the promisee under the contract. (Votaw Precision Tool Co. v. Air Canada (1976) 60 Cal. App.3d 52, 56 [131 Cal. Rptr. 335].) Because the foundation of any right the third person may have is the promisor's contract, "[w]hen [a] plaintiff seeks to secure benefits under a contract as to which he is a third-party beneficiary, he must take that contract as he finds it.... [T]he third party cannot select the parts favorable to him and reject those unfavorable to him." (Sanders v. American Casualty Co. (1969) 269 Cal. App.2d 306, 310 [74 Cal. Rptr. 634].)
Here, the Tenants seek rights greater than those the County possesses under the master lease.
As set forth ante, under paragraph 16, the Lessees at all times are to maintain a schedule of rental rates. If the County's Director determines rents are excessive, the Lessees are to be notified and given an opportunity to justify said rents. If the rents are still determined to be not "fair and reasonable," the Lessees are to modify the rents as directed. Lessees may appeal to the County Board of Supervisors, whose decision shall be final *133 and conclusive. During the pendency of such an appeal, the rates charged are set by the Director.
While the Tenants plead they paid rents in excess of what is "fair and reasonable," nowhere in the complaint is there an allegation that the Lessees charged rents in excess of what the County determined to be "fair and reasonable." By the terms of the master lease, all rents are subject to the County's approval. In disregard of the implicit fact that rents have been at all times "fair and reasonable" to the Director's satisfaction, the Tenants are challenging the rates charged for the four-year period prior to the filing of their action. The County as promisee does not possess such a right. Once the County determined certain rates were "fair and reasonable," the County became bound by those rents, and could not seek a retroactive modification.
As third parties, the Tenants must take the lease as they find it. (Sanders v. American Casualty Co., supra, 269 Cal. App.2d at p. 310.) For the Tenants to seek a redetermination of the rents after the County's approval of all rates is to arrogate to them a right that does not exist under the lease, and further, would subject the Lessees' activities to a two-tier review. Requiring all rents to be approved as "fair and reasonable" twice, once by the County and again by the Tenants possibly through court process, would make the Lessees' performance substantially more burdensome.
A ruling to that effect "would nullify the limited [review] for which [Lessees] bargained and which [the County] may well have held out as an inducement in negotiating the contracts. [Fn. omitted.]" (Martinez v. Socoma Companies, Inc., supra, 11 Cal.3d at p. 403.)
Further, paragraph 16 provides only prospective relief with respect to any rents charged by Lessees in excess of what is "fair and reasonable." Such relief consists of a downward revision of excessive rents, not the money refund sought by the Tenants, and its availability is subject to compliance with paragraph 16's procedures.
The Tenants are incapable of amending their complaint to state a cause of action because under these facts, to grant the Tenants the relief they seek, a third party would be obtaining rights greater than those of the promisee under the contract.
Had the County pursuant to a contract requirement posted approved rental rates, and had the Lessees collected rents in excess of those rates, and had the County refrained from taking any action, Zigas v. Superior Court, supra, 120 Cal. App.3d 827 might well be dispositive. But that is not the case here. *134 The Tenants have not pled that the Lessees charged rents in excess of what the County found to be "fair and reasonable." Nor have the Tenants alleged the County failed to exercise its right to control the rental rates, or even that the County's Director failed to discharge his or her duty properly. The Tenants allege nothing more than a naked conclusion that notwithstanding the procedural safeguards of paragraph 16, the rents paid have been excessive.

5. Tenants cannot state a cause of action based on the equitable doctrine of unjust enrichment.

(11a) As an alternative theory, the Tenants urge the Lessees have been unjustly enriched, thus requiring all excess rentals to be returned to them as the rightful owners.
(12) It is of course the law that when one obtains a benefit which may not be justly retained, unjust enrichment results, and restitution is in order. (1 Witkin, Summary of Cal. Law (8th ed. 1973) Contracts, § 28, p. 45; Rest., Restitution, § 1.) However, the "mere fact that a person benefits another is not of itself sufficient to require the other to make restitution therefor." (Rest., Restitution, § 1, com. c.)
(11b) The Tenants have not offered any legal basis for their assertion that the Lessees' charging County-approved rents was a wrongful acquisition of benefits which the Lessees are not entitled to retain. A mere allegation that Lessees have wrongfully acquired excessive rentals and become unjustly enriched does not entitle the Tenants to relief, as no cognizable legal right of the Tenants has been violated. The sole basis for the Tenants' unjust enrichment claim is the "fair and reasonable" language in the master lease, making this cause of action wholly derivative of the third-party beneficiary claim.
Although a court of equity may employ broad powers in the application of equitable remedies, it cannot create new rights under the guise of doing equity. (Rosenberg v. Lawrence (1938) 10 Cal.2d 590, 594-495 [75 P.2d 1082].) Nor will equity lend its aid to accomplish by indirection what the law forbids to be done directly. (Marsh v. Edelstein (1970) 9 Cal. App.3d 132, 140-141 [88 Cal. Rptr. 26].) Equity follows the law and when the law determines the rights of the respective parties, a court of equity is without power to decree relief which the law denies. (Shive v. Barrow (1948) 88 Cal. App.2d 838, 844 [199 P.2d 693].)
The master lease sets forth the rights of the parties, making the Lessees' rates subject to the County's approval. That agreement does not lend itself *135 to retrospective relief, nor to second-guessing by the Tenants of the Director's determination that the rents are "fair and reasonable," and a ruling to that effect would be in derogation of the rights of the respective parties.
6.-7.[*]
.... .... .... .... .... .... .

CONCLUSION
Where a contract is ambiguous, an allegation of intended beneficiary status must be accepted as correct, unless the pleading places a clearly erroneous construction upon the agreement.
However, a third party cannot assert rights greater than those of the promisee under the contract. For the Tenants to seek retrospective relief, and to claim the right of reviewing all rental rates, notwithstanding a prior determination by the Director that all rents are "fair and reasonable," is to arrogate a right that has no basis in the master lease.

DISPOSITION
The order of dismissal is affirmed. The order re costs is modified, and as modified, affirmed. Each party to bear costs on appeal.
Danielson, J., and Arabian, J., concurred.
A petition for a rehearing was denied June 18, 1986, and the petition of plaintiffs and appellants for review by the Supreme Court was denied July 30, 1986.
NOTES
[]   Pursuant to California Rules of Court, rule 976.1, this opinion is certified for publication with the exception of parts 6 and 7 of the Discussion.
[1]  Here, the trial court judicially noticed the entire master lease in issue.
[*]   See footnote, ante, page 122.
