CHARLESTON, S.C. (Reuters) - The man who plowed his car into mourners at a South Carolina cemetery targeted the graveside service as an act of revenge toward the state mental health agency that had employed the woman being laid to rest, police said on Thursday.

James Kester, 64, is seen in a police booking photo made available after he was arrested following an incident at Greenlawn Memorial Park cemetery in Columbia, South Carolina, U.S. July 20, 2017. Richland County Public Information Office/Handout via REUTERS

James Kester, 64, injured 12 people when he intentionally drove his car into a crowd at Greenlawn Memorial Park in Columbia, the state capital, on Wednesday, police said. They said the mental health agency had once treated Kester’s daughter.

He was arrested on a dozen counts of attempted murder. A judge set bail at $5 million after hearing in court on Thursday how the crime unfolded.

According to witnesses, Kester confirmed that the burial taking place was for a former employee of the state’s mental health department before driving his car through the service, police said.

“He gunned it,” witness Tametha Altman said during the hearing, The State newspaper reported. “After that, it was mass chaos. There were just people thrown everywhere. There were people bleeding everywhere.”

Kester did not appear to know the woman being buried but held a grudge against her longtime former employer, Columbia Deputy Police Chief Melron Kelly said in an interview.

The victims from Wednesday’s crash, aged 11 to 78, were taken to hospitals for non-life-threatening injuries, police said.

Some of the injuries were serious and required surgery, Kelly said.

“It’s not just the physical injuries but injury on an emotional level,” Kelly said of the victims. “The family had to see that happen. In my mind, they weren’t able to pay their proper farewells.”

Kester was convicted of trespassing and disturbing a school in 1990, according to South Carolina Law Enforcement Division records. He also was arrested in 1971 on a rape charge; the records do not say how the case was resolved.

It was not immediately clear if he had a lawyer for the current case.