BOSTON -- More than three months after fiscal year 2018 ended and after some prodding by state financial managers, Massachusetts lawmakers on Monday made quick work of a long-awaited supplemental budget bill to close the books on FY18 and to spend surplus state revenue.

The bills, which emerged from the House Ways and Means Committee around 11 a.m. Monday morning and by 4:15 p.m. was on Gov. Charlie Baker's desk, includes $40 million for local roads and bridges, $10 million to aid Merrimack Valley communities affected by the recent gas disaster and deposits into the rainy day fund that will push that account's balance past $2 billion.

The bill appropriates a total of $540.35 million and Sen. Sal DiDomenico, formerly vice chair of the Ways and Means Committee, said Monday that $347 million of that is deficiency spending to cover shortfalls in various accounts.

Funding for deficient accounts includes $135 million for MassHealth fee for service payments, $100.5 to fund collective bargaining agreements, $32 million for snow and ice removal, $28.6 million for county sheriffs, $10.1 million for the Massachusetts Rehabilitation Commission employment assistance program, and $5 million to support evacuees of last year's hurricanes Irma and Maria, he said.

The bill also spends down the state's surplus from fiscal 2018, which ended on July 1. Massachusetts collected an estimated $1.2 billion more in tax revenue than it had expected last fiscal year, leaving an estimated $200 million in funds that were not earmarked for any particular purpose after about $1 billion was socked away in the state "rainy day" fund or held aside to address underfunded accounts.

"This supplemental budget seeks to strike a careful balance between our immediate needs and our long-term stabilization, all within the context of increased revenues which may not be forthcoming in subsequent years," said Senate President Karen Spilka in a statement. Spilka was in Portugal with a group of senators on Monday when the bill passed.

The Legislature established a $10 million reserve fund for Lawrence, Andover and North Andover, the three towns rocked last month by natural gas explosions and fires. The fund is meant to cover the "costs of commonwealth personnel and overtime expenses, immediate living and medical costs, and costs incurred by" the three municipalities, according to the bill.

Lawmakers are expecting that their $10 million outlay will be reimbursed "by the party deemed responsible for the explosions, whether obtained through fine, penalty, settlement, voluntary contribution or any other form of recovery allowed under state or federal law." A press release sent out Monday by the House and Senate said Columbia Gas will reimburse the funds.

The Legislature also directs $7.5 million in surplus funds to the Executive Office of Education to establish "an infrastructure grant program to assist public schools in enhancing safety and security measures" by upgrading or retrofitting school buildings. The program would pay for, among other things, "classroom door locks, security cameras or active shooter detection systems," according to the legislation.

In July, Baker filed a supplemental budget bill that called for $20 million in matching grants for security and communication upgrades in K-12 schools and at public colleges and universities.

Baker's proposal also included $40 million in additional aid to school districts to hire school counselors. The Legislature opted for a $7.5 million grant program "to assist public school districts in contracting with licensed community-based mental and behavioral health service providers for services in public schools."

Lawmakers also direct some of the state's surplus, $10 million, to a pilot program to be run by non-profit, community-based organizations to help prevent gun violence and other violent crime. The supplemental budget envisions "a neighborhood-based gun and violent crime prevention pilot program" that will specifically work with out-of-school youth and young adults aged 17 to 24 in the cities and towns with the highest rates of violent crime.

The program would pay for things like case workers, mental health counselors, academic supports and research-based practices as long as the grant recipient provides data to show its impact and the Department of Public Health can "ensure that every grant recipient establishes measurable outcomes."

The bill also makes a $10 million transfer to the Community Preservation Trust Fund, which is distributed to cities and towns that use the Community Preservation Act to preserve open space, build affordable housing, and renovate historic buildings and parks, and calls for a $10 million transfer to the Life Sciences Investment Fund.

"This budget invests in key House priorities including gun safety, infrastructure and responding to emergency incidents, while helping to fortify the state's future fiscal health," House Speaker Robert DeLeo said in a statement. "These investments will make communities safer, improve our roads and provide protections for those most in need."

The Senate will get $2 million through the bill, money which Spilka said would be used "for a number of end-of-year expenses for the Senate, primarily focused on technology upgrades and HR improvements." Among the expenses, the Senate president said, are technology and infrastructure upgrades to the Senate broadcast studio in connection with the ongoing Senate Chamber renovation.

Spilka said the money will also be used to "modernize [human resources] in line with the frameworks of both the sexual harassment report and the pay equity act."

Senate Minority Leader Bruce Tarr took to the floor during what he called a "highly unusual" informal session Monday to urge inclusion of funding for three accounts that he said had been removed in the Ways and Means rewrite -- regional school transportation, reimbursement of charter school tuition paid by local school districts, and compensation for a shortfall in last year's special education circuit breaker reimbursement.

Tarr moved to send the "defi-supp" bill -- a portmanteau of deficit and supplemental -- back to the Ways and Means Committee. After the motion failed, the Gloucester Republican did not object to the bill's initial approval or passage. In an informal session, an objection by one member can halt a bill's progress, but Tarr opted to "not arrest the whole process," he told the News Service, saying he had only sought "just a little more time."

Monday's action on the fiscal 2018 closeout bill came at the first available opportunity after the state's auditor, treasurer and comptroller on Friday raised concerns about the stalled budget bill.

Comptroller Thomas Shack had been trying to warn lawmakers that inaction on a bill to close the books on fiscal year 2018 and spend surplus funds was putting his ability to meet a financial reporting deadline prescribed by the Legislature in serious doubt. It's the same issue he's been raising with legislative leaders annually for four years.

Shack's office must close the books on the fiscal year that ended June 30 and file the annual Statutory Basis Financial Report by Oct. 31, and he said that having the Legislature pass its final supplemental budget by Aug. 31 is an industry best practice because it allows his team enough time to properly prepare the financial report, which needs to be independently audited before its filing.

"This is the fourth fiscal year that I've operated as the commonwealth's comptroller and this is the fourth year under my comptrollership that we will not meet the statutory deadline," he said Friday at a meeting of the Comptroller Advisory Board. "I would reiterate that such late activity is really perilous. It's a well-known risk within the audit world that if you do not meet your own statutory obligations you may well subject yourself to really, really significant scrutiny."

Gov. Baker now has 10 days to review the supplemental budget before signing it or vetoing some or all of it.