EDMONTON, Alberta, April 24 (UPI) — Former Guantanamo inmate Omar Khadr was granted bail in a Canadian court Friday, after 12 years of imprisonment.

Alberta Justice June Ross’ decision paves the way for a hearing May 5 in which Khadr’s conditions of release will be decided.

Khadr, 27, a Canadian citizen, was captured by U.S. military forces in 2002 during a firefight in Afghanistan in which a U.S. soldier, Christopher Speer, was killed. Then age 15, he was charged with five offenses under the Military Commissions Act, which was written after Khadr’s alleged crimes, convicted and sent to the prison at Guantanamo Bay, Cuba. His lawyer in the United States is arguing he should not have been retroactively prosecuted for a war crime.

In 2010, Khadr pleaded guilty to throwing the grenade that killed Speer, part of a plea deal allowing him to return to Canada to finish his sentence. His release was scheduled for 2018. He has been incarcerated at the Bowden institute in Alberta.

He requested bail while appealing the convictions, and under a plan submitted to the Alberta court, will live with his lawyer, Dennis Edney. His family, with whom he will communicate through the Internet, resides in Toronto.

The prosecution can still appeal any release order.