(CNN) —  

A gunman killed five people before taking his own life Wednesday in what appeared to be targeted attacks related to a domestic violence case, authorities said Thursday.

The shooting spree unfolded in less than 40 minutes across three locations in proximity to each other near Bakersfield, California, Kern County Sheriff Donny Youngblood said.

The gunman, identified as Javier Casarez, 54, killed himself as a sheriff’s deputy confronted him, Youngblood said.

Along the way, the gunman stole a vehicle from a woman and her child but let them live, Youngblood said. He told the woman something to the effect of “he wasn’t a bad person,” Youngblood said.

Javier Casarez
Javier Casarez
PHOTO: Kern County Sheriff

Police are investigating the relationship between the gunman and the victims. But it appears Casarez and victim Petra Maribel Bolanos De Casarez, 45, had begun to divorce about four months ago, the sheriff said. They were in “divorce proceedings” and she had recently sought a hearing related to child support and property, he said.

“It appears to be there’s more than just a husband and wife having a fight, because other people were targeted. There’s a reason for that, and we need to find that reason,” the sheriff said.

The pair arrived at T&T Trucking at 5:15 p.m. on Wednesday and confronted an employee identified as Manuel Contreras, the sheriff said. Casarez shot Contreras with a .50-caliber handgun and then Bolanos, Youngblood said.

Another man, identified as Antonio Valadez, fled the building. The gunman followed him in his car to the front of a nearby hunting equipment shop and shot him, Youngblood said.

The gunman then drove to a nearby home, where he fatally shot Eliseo Cazares, 57, and his daughter, Laura Garcia, 31, as she tried to intervene, the sheriff said.

He left the home and hijacked a vehicle with a woman and child inside, but let them go, Youngblood said. He headed to a nearby highway, where he saw a deputy and pulled over into a lot.

As the deputy drew a weapon and confronted him, the gunman shot himself fatally in the stomach, Youngblood said.

Investigators aren’t sure about a motive, but it appears the former couple had some type of connection to the trucking company, and the shootings were planned, Youngblood said.

CNN’s Jennifer Selva and Jack Hannah contibuted to this report.