A federal judge Tuesday upheld most of New York’s new gun control law, rejecting arguments that its bans on large-capacity magazines and the sale of some semi-automatic rifles violate Second Amendment rights.

Judge William Skretny in Buffalo concluded those provisions are constitutional because they’re related to achieving an “important governmental interest” in public safety. Those two features make guns more lethal, he wrote, citing testimony submitted in the case.

The law “applies only to a subset of firearms with characteristics New York state has determined to be particularly dangerous and unnecessary for self-defense,” Skretny wrote. “It does not totally disarm New York’s citizens, and it does not meaningfully jeopardize their right to self-defense.”

Skretny upheld the ban on magazines that hold more than 10 bullets, but he struck down a restriction on gun owners loading more than seven bullets in legal 10-round magazines. He said that appears to be “an arbitrary number.”

The law was adopted last January after the mass shooting at Sandy Hook Elementary School in Newtown, Conn., by a gunman police said used a semi-automatic rifle and 30-round magazines to kill 20 children and six adults.

“Of course, this is only one incident,” Skretny wrote. “But it is nonetheless illustrative. Studies and data support New York’s view that assault weapons are often used to devastating effect in mass shootings.”

He cited a study listing 62 mass shootings in the U.S. since 1982, involving the murders of four or more people, that concluded assault weapons, high-capacity magazines or both were used in more than half of them.

The New York affiliate of the National Rifle Association, sportsmen’s groups, firearms businesses and gun owners filed the lawsuit. They argued that the new statute was unconstitutional, because it prohibits citizens from keeping commonly used firearms for home defense and other lawful purposes.

The law redefined an assault weapon as a semi-automatic rifle that can accept a detachable magazine and has one military-style feature such as a pistol grip or folding stock. That definition applies to popular AR-15s and several other rifles, pistols and shotguns, which can no longer be sold legally in New York. The law requires an estimated 1 million residents who bought one previously to register it by April 15.

The rifle association and Gov. Andrew Cuomo’s office did not immediately comment. Cuomo’s staff wrote the law, which he pushed through the Legislature.