
639 A.2d 103 (1994)
A.F.A.B., INC., d/b/a A.F.A.B. Construction
v.
TOWN OF OLD ORCHARD BEACH.
Supreme Judicial Court of Maine.
Argued January 4, 1994.
Decided March 28, 1994.
*104 Neal L. Weinstein (orally), Old Orchard Beach, for plaintiff.
David R. Ordway (orally), Ordway & Associates, Biddeford, for defendant.
Before WATHEN, C.J., and ROBERTS, GLASSMAN, CLIFFORD, COLLINS, RUDMAN and DANA, JJ.
CLIFFORD, Justice.
Plaintiff A.F.A.B., Inc. (AFAB) appeals from a judgment of the Superior Court (York County, Fritzsche, J.) in favor of defendant Town of Old Orchard Beach (Town). The Superior Court held that, although AFAB had proven all of the requirements of unjust enrichment against the Town, municipal immunity precludes AFAB's recovery in this case. Because we conclude that municipal immunity is not necessarily a bar to recovery for unjust enrichment in every case, we vacate the judgment and remand to the Superior Court.
In the spring of 1988, the Town owned the Ballpark in Old Orchard Beach, and had entered into a purchase and sale agreement with Stadium Partners, Inc. (Stadium).[1] Stadium orally agreed with AFAB to have AFAB perform repairs and renovations to the Ballpark in time for the beginning of the baseball season. AFAB was aware of a provision in the purchase and sale agreement that the Town would reimburse Stadium for the costs of repairs should the sale of the Ballpark to Stadium not take place. Moreover, there was testimony that the Town manager subsequently had promised AFAB that any sale of the Ballpark would include a provision requiring the purchaser to pay AFAB what was owed to it. The sale to Stadium did not take place; the Town operated the Ballpark that summer and then sold it to Sea Pac. That sale, however, absolved Sea Pac of liability for expenses incurred prior to the sale. Although AFAB completed the work in a competent manner and within a tight timetable, and the park was ready for the 1988 baseball season, Stadium paid only $10,000 of a $61,749 bill, leaving an outstanding balance of $51,749. AFAB filed a mechanic's lien certificate against Stadium, but the lien claim was not perfected.
AFAB brought a complaint against Stadium and the Town. A default judgment was entered against Stadium for $51,749 and remains unpaid. The Superior Court entered a judgment for the Town on AFAB's claims of breach of contract and unjust enrichment.
Concluding that the Superior Court incorrectly granted the Town's motion for a judgment on the issue of unjust enrichment, we vacated that judgment. A.F.A.B., Inc. v. Town of Old Orchard Beach, 610 A.2d 747 (Me.1992) (AFAB I). On remand following a nonjury trial, the Superior Court found that AFAB proved all three elements of unjust enrichment: that a benefit had been conferred on the Town by AFAB, that the Town appreciated or knew of the benefit, and that it would be inequitable for the Town to retain the benefit of the work without payment of its value. Nevertheless, the court entered a judgment against AFAB in favor of the Town because of its understanding of Maine law according municipalities immunity from claims arising from implied contracts.[2] To avoid the necessity of an additional trial in the event that AFAB prevailed in this appeal, the court determined AFAB's unjust enrichment damages to be $35,000. In doing so, the court excluded from its consideration *105 AFAB's profits and overhead costs. This appeal followed.

I.
We agree with AFAB's contention that governmental entities should not be immune from liability as a matter of law in all cases and circumstances when the municipality has received and retained a valuable benefit without paying for the value of that benefit.
When one party unjustly benefits from labor and materials rendered by another with the expectation of payment, the law may impose a promise on the part of the recipient to pay the value of the benefit conferred. See Estate of White, 521 A.2d 1180, 1182 (Me.1987). "The rationale for allowing recovery under the doctrine of unjust enrichment is that it is contrary to equity and good conscience for a party to retain a benefit at the expense of the other party."[3]Id. at 1182-83.
The Superior Court correctly noted that municipalities have heretofore generally been immune from recovery under quantum meruit. See Watts Detective Agency, Inc. v. Inhabitants of County of Sagadahoc, 137 Me. 233, 242, 18 A.2d 308 (1941); Portland Tractor Co., Inc. v. Inhabitants of the Town of Anson, 134 Me. 329, 332, 186 A. 883 (1936); Michaud v. Inhabitants of St. Francis, 127 Me. 255, 259, 143 A. 56 (1928). Those cases have been based on express or implied-in-fact contracts between municipalities and plaintiffs and have protected municipalities from paying for unauthorized services. Watts, 137 Me. at 242, 18 A.2d 308 (recovery denied to plaintiff who had performed services for a county pursuant to an employment agreement entered into by a county attorney who lacked authorization to bind county to expense); Portland Tractor, 134 Me. at 332, 186 A. 883 (denial of recovery because contract with plaintiff exceeded legal level of indebtedness, had been executed by selectmen lacking authorization, and was void); Michaud, 127 Me. at 259, 143 A. 56 (denial of recovery to plaintiff school teacher who relied on promise of two unauthorized members of school committee because employment by those acting without legal authority creates no municipal liability); Van Buren Light & Power Co. v. Inhabitants of Van Buren, 116 Me. 119, 123, 100 A. 371 (1917) (no quantum meruit recovery when plaintiff utility reinitiated service without Town's authorization after Town breached and voided contract). These cases are consistent with the law protecting municipalities from liability under illegal, void, or unauthorized contracts. See Peoples Heritage Bank v. City of Saco, 566 A.2d 745, 746-47 (Me.1989).
Although courts are reluctant to impose contractual liability on a municipality when the contract on which the liability is based has not been properly authorized, or is void or illegal, in other contexts we have moved away from complete immunization of municipalities under the common law from liability in every case regardless of the circumstances. See, e.g., City of Auburn v. Desgrosseilliers, 578 A.2d 712, 714-15 (Me.1990); Maine School Admin. Dist. No. 15 v. Raynolds, 413 A.2d 523, 533 (Me.1980). For example, in Raynolds, this court rejected the common law principle that equitable estoppel can never be applied against any governmental official or agency acting in the discharge of any governmental function. We held that depending on the circumstances, including the governmental official or agency acting, the function being discharged, and public policy considerations, equitable estoppel may be applied to activities of a governmental official or agency in the discharge of governmental functions. Raynolds, 413 A.2d at 533. We applied this same principle in Desgrosseilliers, in which we concluded that equitable estoppel should apply to preclude the City of Auburn's enforcement of a zoning *106 ordinance against defendants who had been misled by the City into believing that they were in compliance, and who made substantial investments in reliance on the City's actions. 578 A.2d at 715.
Likewise, when a plaintiff has proven that a benefit has been conferred on a municipality under circumstances that would otherwise make it inequitable for the benefit to be retained without payment were the defendant not a town or city, the plaintiff should not be barred from recovering the value of that retained benefit solely because the defendant is a municipality. Rather, the fact that the defendant is a municipality, and therefore the taxpayers will bear the burden of compensating the plaintiff should recovery be allowed, is one of the circumstances appropriately to be considered in determining whether the municipality should be accountable for a claim of unjust enrichment.[4] We therefore remand to the Superior Court for its consideration of all the circumstances of this case to determine if it would be equitable to bar recovery against the Town by AFAB. The court is left to its own discretion to decide whether to open the record to take additional evidence.

II.
Even though it entered a judgment for the Town, the Superior Court addressed the issue of damages to eliminate the necessity of an additional hearing in the event that AFAB should prevail on this appeal. Recovery under the doctrine of unjust enrichment is measured by the value of the benefits that the plaintiff proves are actually received and retained by the defendant, Steel Serv. Ctr. v. Prince Macaroni Mfg. Co., 438 A.2d 881, 882 (Me.1981), and the court expressed a general understanding of this principle. The cost of improvements, i.e., the value of the work, labor, services, and materials furnished, is evidence that may be considered in determining the value of the benefit conferred. AFAB I, 610 A.2d at 750; see 66 Am.Jur.2d Restitution and Implied Contracts § 166 (1973). Indeed, the court's determination of damages of $35,000 appears to be based solely on the cost of the improvements. The court appears to have categorically excluded from consideration what it found to be AFAB's overhead expenses and profit. Such a blanket exclusion of a plaintiff's overhead, costs, and profits is improper unless the court determines that they have no meaningful relationship to the value of the benefit conferred and the extent to which a defendant has been enriched. Therefore, on remand, should the Superior Court determine that AFAB should recover on its claim for unjust enrichment, the issue of AFAB's damages should be reconsidered. In doing so, the court in its discretion may take additional evidence.
The entry is:
Judgment vacated. Remanded to the Superior Court for further proceedings consistent with the opinion herein.
All concurring.
NOTES
[1]  Although our previous opinion in this case, A.F.A.B., Inc. v. Town of Old Orchard Beach, 610 A.2d 747 (Me.1992), referred to Stadium Partners, Inc. as Stadium Enterprises, the record indicates that the entity's correct name is Stadium Partners, Inc.
[2]  The issue of governmental immunity was not raised until the case was remanded for trial following our decision in AFAB I.
[3]  Although the terms "unjust enrichment" and "quantum meruit" are often used synonymously, the distinction between them is legally significant. Quantum meruit denotes recovery for the value of services or materials provided under an actual, implied-in-fact contract. Martin v. Campanaro, 156 F.2d 127, 130-31 n. 3 (2d Cir.1946). Unjust enrichment describes recovery for the value of the benefit retained when there is no contractual relationship, but when, on the grounds of fairness and justice, the law compels performance of a legal and moral duty to pay. Id.; Saunders v. Saunders, 90 Me. 284, 289, 38 A. 172 (1897); 66 Am.Jur.2d Restitution and Implied Contracts § 166 (1973). The distinction was not clearly made by the parties in this case.
[4]  The court should take into consideration all the relevant circumstances in determining whether a governmental entity should be immune from liability for the receipt and retention of a benefit. On the one hand, when a municipality has been unjustly enriched, principles of common justice, applicable alike to natural and artificial persons, support imposing liability. 10A E. McQuillin, The Law of Municipal Corporations § 29.110 (3d ed. 1990). On the other hand, "the salutary protection the law secures to citizens against capricious governmental behavior" may support imposing municipal immunity from claims for unjust enrichment. Hazle Township v. City of Hazleton, 45 Pa.Cmwlth. 370, 407 A.2d 893, 895 (1979). Among other circumstances that may be considered is whether the municipality was acting in its governmental capacity or a proprietary role. See J.C. Griffith, Local Government Contracts: Escaping from the Governmental/Proprietary Maze, 75 Iowa L.Rev. 277, 284 (1990). Rather than municipalities benefiting from a blanket immunity, a court should properly weigh all the facts and circumstances applicable to a particular case before determining whether a city or town should incur liability for being unjustly enriched.
