A former Army medic pleaded guilty to second-degree murder on Monday, years after he plotted the murder of his wife with a woman he was having an affair with.

Michael Walker — who in 2017 was demoted from sergeant to private and dishonorably discharged from the Army — was charged with first-degree murder, Hawaii News Now reported, but took a plea deal for the chance of a lesser sentence. Alisa Jackson, the woman that Walker was having an affair with at the time, already pleaded guilty in 2015 to stabbing his wife Catherine Walker, the Associated Press reports.

Jackson and Walker met on a dating website in September 2014, the AP reports, and began plotting the murder of his wife “in emails, during in-person discussions, and in text messages.”

Walker's “deepest desire” was to have his wife gone, Assistant U.S. Attorney Tom Brady said on Monday, according to the AP, which Walker told a judge on Monday meant that he “wanted her dead.” He was also being paid for sex with men; he told one man that he had unpaid sex with that his wife didn't know he was bisexual and he wanted “to be free to live life how I want to,” the AP reports.

“I have a problem. I'm a sex addict,” Walker said in a 2014 interrogation, according to CBS.

Walker told Jackson that due to financial concerns he couldn't divorce his wife, and that he would receive $400,000 in life insurance. The night that Catherine Walker was killed, her husband and Jackson met at a gym parking lot where they devised a text message code that Walker would send to signal to Jackson how she should get into the house to stab his wife — “good” meant that Jackson would come through a window, and “bad” meant that she should use the key.

He later texted “bad,” and Jackson came to the home around midnight, entering with the key, grabbing a knife inside the home and going upstairs, stabbing Catherine. Per the AP, Jackson “waited a half-hour to make sure she was dead.” Walker was reportedly working at Tripler Army Medical Center emergency room at the time of the murder to ensure an alibi.

Brady said in court on Monday that Walker knew Jackson heard voices, and was mentally ill.

Walker was found guilty in 2016 of child pornography charges that came forward during the murder investigation, the AP reports. He was later dishonorably discharged and reduced in rank from sergeant to private in 2017 after he was convicted of “sexually abusing a child, physically assaulting a child, and wrongfully communicating a threat,” per the AP. He also received 10 years confinement.

Per CBS, the couple are expected to face sentencing on February 10; Jackson is expected to receive 30-33 years in prison, and Walker is expected to receive 24-30.