A man told a Kansas court on Tuesday that he chopped up his wife’s body in a hotel after she killed herself to protect his family.

Justin Todd Rey, 36, appeared in front a Johnson County judge to explain during his preliminary hearing why he spent eight hours hacking Jessica Rey’s body into pieces last October, The Kansas City Star reported.

“It’s something I had to do,” Rey said in court. “My family is very dear to me. It’s something I had to do to protect my family.”

Jessica Rey gave birth to a baby in a bathtub at a Kansas City, Mo., hotel and then killed herself. Justin Rey, instead of calling police for help, dismembered his wife’s body so he could take her remains to Arizona while caring for his newborn and two-year-old daughter.

Authorities located the body parts in bags at a storage shed in Lenexa, Kansas.

MAN IN '15 MOST WANTED' FUGITIVE LIST CAPTURED AFTER 16 YEARS ON THE RUN FOR MURDERS

Rey, who is not charged in his wife’s death, entered a not guilty plea Tuesday for charges of two counts of aggravated child endangerment and two counts of contributing to a child's misconduct. He was also charged with abandonment of a corpse in Missouri.

Rey had initially provided officials with conflicting reports on what happened the day his wife died. He previously said she died in childbirth, but Lenexa police detective Shannon Murphy testified that Rey told her his wife had killed herself.

After having his children pose for photographs with her body, Rey said he "skinned her like a fish," according to Murphy. She said Rey flushed body parts that would not fit in containers down the toilet.

Police discovered Rey and his children at a storage facility after receiving calls. The officer said Rey’s daughter “almost looked like she had cancer” with bags under her eyes and thinning hair. Several witnesses said the newborn also had a serious eye infection.

CANADA MAN GETS PRISON TIME FOR SMUGGLING GUNS IN LIBRARY ON BORDER

On Tuesday, Rey denied putting his children at risk and living at the storage facility, as some witnesses claimed. He said they had been at the facility for about 11 hours and was preparing the family for a trip to Arizona, where he intended to give his wife a proper burial.

"I didn't endanger my children," he testified. "My children were perfectly healthy."

Rey also denied flushing anything but a placenta down the toilet.

His trial on the Kansas charges was scheduled for Nov. 5.

Separately, Rey was charged in November in California in the death of Sean Ty Ferel, a Palm Springs resident who disappeared after vacationing with Rey in 2016. Ferel's body hasn't been found, but his blood was detected in the trunk of his vehicle after Rey was involved in an accident months after Ferel disappeared.

The Associated Press contributed to this report.