The U.S. Department of Justice and the city of Baltimore announced an agreement to reform the city’s troubled police department on Thursday. The 227-page document lays out a detailed plan for the Baltimore police to try to correct egregious violations of constitutional rights, racial disparities in their practices, excessive use of force, and a culture of retaliation against whistleblowers. The agreement could represent one of the last hurrahs for the police-reform movement before the Trump administration takes office.

The agreement, which the city voted to fund Thursday morning, even before it had been made public, resolves a federal investigation that began with the death of Freddie Gray in police custody in April 2015. That death provoked widespread demonstrations in the streets of the Charm City, and some rioting, drawing the spotlight to a long history of racial division and unequal policing in Baltimore. While a prosecutor’s bid to convict officers for their role in Gray’s death failed, the Justice Department produced a stomach-churning report last August.

The report found, for example, that Baltimore police tended to make frequent stops and arrests, even when there was no useful law-enforcement reason for it, and often at the expense of community relations. But the problem ran much deeper: Police often made stops and arrests that fell afoul of constitutional protections. Many stops ended with no citation or arrest, and even when they did, booking officers often rejected charges as too flimsy—doing so 11,000 times between 2010 and 2015. Sometimes cops rounded up large numbers of people, then “unarrested” them when they determined they had no grounds for it. Justice also found that people were often arrested simply for exercising their First Amendment rights by criticizing or talking back to officers.

But those most likely to be arrested were disproportionately African Americans and people in heavily African American neighborhoods. Blacks were more likely to be arrested for minor, apparently pretextual violations like throwing dice—for which 99 percent of arrestees were black. The problem was so bad that boilerplate language provided to officers for logging arrests assumed by default that suspects would be black males. African Americans were also more likely to be exposed to excessive use of force.

Police were routinely mishandling cases with mentally disabled suspects, and they belittled or pressured victims of sexual assault. And when some officers tried to speak up, they were subject to reprisals from fellow officers. DOJ surmised that the numbers it received from BPD probably underestimated the problem, since there appeared to be many encounters that were not properly logged.

The agreement reached Thursday is 50 percent again longer than the initial report, and offers a series of detailed prescriptions intended to solve the problems that report had documented. Although “the City and BPD did not and do not admit or agree with the findings in the United States’ Report,” it says, they “recognized that the United States’ findings raised issues of importance to the City, BPD, and the community that should be addressed, and they committed to address each of the concerns raised.”

Many of the clauses in the report are fairly standard—like a commitment to better training, or homage to the importance of community-oriented policing, today’s big buzzword in law-enforcement reform. But others are more specific. “BPD will ensure that it conducts all Investigatory Stops, Searches, and Arrests in accordance with the rights secured or protected by the Constitution, and state and federal law,” the agreement states. Officers will have to tell individuals stopped for voluntary interviews that providing ID is optional, and refusing to cooperate will not justify detention, arrest, search, or issuing a ticket. People who run from the police cannot be stopped or arrested simply for that fact, as Freddie Gray was.

Moreover, an officer must have “specific and articulable facts, that a person has committed, is committing or is about to commit a crime” in order to detain them or conduct an investigatory stop. Police will have to document each of these stops, and they will not be allowed to use boilerplate language.

An individual’s presence in a location, such as an area police deem to be high in crime or proximity to a crime, will not be enough to justify a stop or detention. Except in certain circumstances, police will also have to seek a superviser’s permission before arresting people for a range of crimes that might actually represent pretextual stops, including obstructing, hindering or resisting an officer; disorderly conduct; gambling; failure to obey an officer or making a false statement to an officer; and misdemeanor trespassing. Whenever police arrest someone but let them go without charging them, whether for lack of probable cause, an identity issue, or other reasons, the department will have to report that to monitors.

Police face new restrictions on unholstering their service guns. They will be prohibited “from exhibiting or pointing a firearm unless the officer reasonably believes that the situation may escalate to create an imminent threat of serious bodily injury or death to the officer or another person.” There are new guidelines for dealing with people in mental-health crises. The procedure for dealing with victims of sexual assault is being overhauled.

One set of new rules focuses on the central question in Gray’s death and the trial of officers. Gray was apparently healthy when he was arrested and placed in a police wagon, but by the time he was removed less than an hour later, his spinal cord was nearly severed. He died after a week in a coma. But the question of how Gray had been injured was never resolved. Contrary to department regulations, he was not seatbelted in, though officers said that was common. Reform advocates, and prosecutors, suggested that Gray had received a “rough ride” in the back of the van, a practice in which police drive erratically so as to bang a prisoner around. But they couldn’t prove that in court. New regulations are designed to avoid that sort of problem. Officers will be required to seatbelt prisoners in, and vans will be equipped with cameras to track what’s going on in the back.

It is not a coincidence that the agreement between Baltimore and the Justice Department arrives in the final 10 days of the Obama administration. DOJ consent decrees have proven to be one of the most common, and most consistently effective, tools for forcing police departments to reform themselves and end abuses, particularly with regards to unfair police practices toward African Americans. (That is not to say that such consent decrees are a silver bullet: The Cleveland Police Department was under one in the mid-2000s, emerged from it, and then was placed under another in 2015.)

In December, The Washington Post reported that the Justice Department was rushing to finish a consent decree with Baltimore and another with Chicago, another police department with a troubled relationship with African American citizens. The Trump Justice Department is not expected to be nearly as active as the Justice Department under Obama Attorneys General Eric Holder and Loretta Lynch. In his prepared remarks before a confirmation hearing this week, Attorney General-designate Jeff Sessions complained that “law enforcement as a whole has been unfairly maligned and blamed for the actions of a few bad actors and for allegations about police that were not true.”

Last fall’s Justice Department report on Baltimore, as well as its earlier report on Ferguson, Missouri, show just how appalling and systemic the flaws in police departments can be. But starting on January 20, the push to fix those problems will no longer be able to rely so heavily on the investigative and punitive muscle of the federal government.