A sex offender from Dundee has failed in his bid to strike out the need for a rehab course that could see him freed from prison.
Andrew Brown was handed an order for lifelong restriction (OLR) in 2017 after being convicted of a number of sex offences.
The orders are only handed out to the most serious sexual offenders and see them imprisoned indefinitely.
Even if they are released, OLR offenders remain electronically tagged for the rest of their lives.
Brown became eligible for parole earlier this year after serving the four-and-a-half year punishment part of his sentence but was refused his freedom in April.
The parole board had been unable to assess whether he still posed a risk to the public because he had not completed any rehabilitation courses - prompting a legal challenge to the Scottish Government by the sex offender.
Lawyers acting on Brown's behalf claimed he stood no chance of being released until he completed a rehabilitation course for sex offenders called Moving Forward: Making Changes.
But the course was heavily subscribed, with 1,200 sex offenders in Scottish prisons at the time, and a prioritisation system saw Brown pushed further down the queue in favour of other prisoners who had fixed release dates.
In 2019 he was in position 189 out of 257 for part of the course - and prison bosses said it could only finish 60 courses a year. At present, he does not have a date for when he can start the course.
In the Outer House of the Court of Session, lawyers acting on Brown's behalf called for the Scottish Government to admit that it was not properly supporting prisoners in their rehabilitation.
Scottish ministers, they said, had forced Brown to wait an "irrational" amount of time because he was "leapfrogged" in the queue for the course by other prisoners serving shorter sentences.
Brown's representatives branded the whole process "unfair" and in breach of his human rights.
However, lawyers for the Scottish Government said that they were working to address delays on the waiting list, which they said had been caused by greater demand.
Scottish Prison Service bosses are in the process of replacing the programme with two new schemes, including one for those assessed to pose less risk of harm to the public.
Appeal judge Lady Wise ruled that the rehab scheme was not showing symptoms of "systemic failure", and refused Brown's appeal.
She said of Brown, named in papers as the petitioner: "Delays of the type complained of are unsatisfactory, but I am not persuaded that the petitioner has shown a failure to provide the requisite systems and resources to address the problem."
Get the latest Dundee Live news sent straight to your inbox. Sign up for our daily news updates .