A former U.S. Customs and Border Protection watch commander stationed at the Long Beach port was sentenced Monday to 31 months behind bars for running an illegal online gun business, failing to disclose foreign contacts and cheating on his taxes.

Wei Xu, 57, was also sentenced by U.S. District Judge R. Gary Klausner to pay $128,407 in restitution to the Internal Revenue Service and serve three years on supervised release following prison.

Prosecutors said the Santa Fe Springs man had an “inflated sense that he was above the law” and was “clearly motivated by greed.”

Xu pleaded guilty in July to four felonies: unlawfully engaging in the business of dealing in firearms, unlawfully possessing unregistered firearms, lying to a federal agency, and tax evasion. The charges carry up to 25 years behind bars, but prosecutors said in the plea agreement that they would recommend about three and a half years and restitution of $128,407 to theInternal Revenue Service.

In a statement to the court, Xu—who has remained in federal custody since his arrest in February—apologized, telling the judge that he used his authority and knowledge of firearms “in the wrong way. I cannot forgive myself.”

Xu admitted that he sold at least 99 firearms without the required federal license between the late 1990s and his arrest. To increase the profit margin of his illegal side business, Xu exploited his status as a law enforcement officer to purchase and then transfer “off-roster” handguns that cannot be sold to the general public by a federal firearms license dealer, according to the plea agreement.

Xu also sold or transferred firearms within days or weeks from the date he purchased them and operated several accounts on internet market places to advertise his firearm business, according to court documents.

In July and August 2018, Xu sold four firearms to an undercover agent posing as a buyer, and unlawfully sold three of the firearms out of the trunk of his car, prosecutors said.

Xu’s crimes were a “betrayal of his oath to uphold the law,” according to the government’s sentencing memorandum, filed in Los Angeles federal court.

The firearms included an “off-roster” pistol, high-capacity magazines, and a short-barreled rifle, the plea agreement states. A search of Xu’s home recovered more than 250 firearms, including 41 fully automatic firearms or machine guns and two additional short-barreled rifles—none of which were registered with the Bureau of Alcohol, Tobacco, Firearms and Explosives as required by federal law, according to prosecutors.

Xu also admitted that he lied on three questionnaires submitted to the Office of Personnel Management to obtain a secret-level security clearance. OPM is a federal agency that oversees applications for security clearances for federal government employees.

Finally, Xu admitted in his plea agreement that he willfully evaded payment of federal income tax from 2005 to 2017 by setting up a sham company used to claim fictional ordinary business losses to offset his ordinary income and fraudulently evade tax due to the IRS, according to the U.S. Attorney’sOffice.

After imposing sentence, Klausner told the defendant that “everyone in life will sometimes make mistakes” and that Xu could be proud of owning up to his crimes and paying “for the wrongs that you did.”