Boise, Idaho — A federal appeals court panel says Idaho’s ban on spying at farms, dairies and slaughterhouses violates free speech rights.

The 9th U.S. Circuit Court of Appeals on Thursday ruled that sections of the law illegally targeted free speech and investigative journalism.

However, the panel also ruled the law correctly criminalized those who made false statements to obtain records at an agricultural facility.

Idaho lawmakers passed the law making it a crime to surreptitiously videotape agriculture operations in 2014 after the state’s $2.5 billion dairy industry complained that videos of cows being abused at a southern Idaho dairy unfairly hurt their businesses.

The Animal Legal Defense Fund sued the state, and in 2015 a federal court invalidated the law after finding that it violated the First Amendment.