A Cambodian-born man who had come to the U.S. with his parents at the age of 1, and who had been a U.S. citizen since he was 12 years old but was nonetheless targeted for deportation, returned home to California on Wednesday via San Francisco.

Sok Loeun, 35, self-deported five years ago after U.S. Customs and Border Protection (CBP) agents threatened to deport him, but with the help of a lawyer he was able to clear up a clerical error about his citizenship status that dated back over two decades. And the story, in which he himself wasn't aware that he was a legal citizen, highlights the vagaries of the U.S. immigration system and the complexities that many immigrants aren't even aware of, as the Chronicle reports.

Loeun, who grew up in Fresno, was convicted on a marijuana possession charge in 2012, setting in motion a process to revoke his legal residency status under the Obama-era CBP. Three years later, in 2015, Loeun traveled to Cambodia with his family, but upon trying to return to the U.S. he was denied entry and told if he tried to enter he could be deport. Like other immigrants with questionable residency status, Loeun decided to voluntarily move to Cambodia, a country where he had not grown up, because he was a single dad at the time and didn't want to spend untold months in detention. Ever since, he's been living and working in Cambodia, unaware that he could, in fact, come right back. He remarried, had another child, and then heard about a legal workshop being held in Phnom Penh, hosted by the San Francisco-based Asian Law Caucus. It was there that lawyer Anoop Prasad helped Loeun figure out that he was actually a U.S. citizen.

Loeun had become a citizen under the complicated program known as derivative citizenship, in which children under 18 automatically receive citizen status if one of their parents does. Loeun's mother became a U.S. citizen in 1996, after fleeing the Khmer Rouge, ending up in a refugee camp in Thailand, and emigrating with her family to the U.S. in 1985. Leoun was 12 at the time, but neither he nor his mother were aware of the derivative citizenship category and he had never received any documentation of it. Also, workers at the former Immigration and Naturalization Service, which is now part of the Office of Homeland Security, had failed to change the official record for Loeun after his mother became a citizen.

As Sarah Pierce, a policy analyst for the Migration Policy Institute, explains to the Chronicle, it's "very understandable that foreign nationals themselves wouldn't know whether they had acquired citizenship, especially if they have other IDs."

Now, Loeun says he is very grateful to be back in California. And all is well. He was greeted Wednesday by 75 friends and family members at SFO, drums included.