The appellant in this case was sentenced to an extended sentence of ten years imprisonment, comprising a custodial term of seven years and an extension period of three years. He was released on licence after serving two thirds of the custodial term, but was recalled to custody after committing a further offence. He then remained in prison until the sentence had been served in full. In these proceedings, he complains that he was not provided with appropriate rehabilitation courses following his recall to prison, contrary to article 5 of the European Convention on Human Rights and Fundamental Freedoms (the Convention), as given effect in our domestic law by the Human Rights Act 1998. The principal issue arising in the appeal is whether the duty under article 5 to provide prisoners with a real opportunity for rehabilitation applies to prisoners serving extended sentences. The appeal also provides an opportunity to consider the approach adopted by this court in R (Kaiyam) v Secretary of State for Justice [2014] UKSC 66; [2015] AC 1344 in the light of the more recent case law of the European Court of Human Rights. Article 5 The essential aim of article 5 is to confer protection against arbitrary or unjustified deprivation of liberty. Article 5(1) provides a list of permissible grounds for deprivation of liberty, each of which is qualified by the requirement that the detention is lawful and in accordance with a procedure prescribed by law. In the present case, it is article 5(1)(a) which is relevant: 1. Everyone has the right to liberty and security of person. No one shall be deprived of his liberty save in the following cases and in accordance with a procedure prescribed by law: the lawful detention of a person after conviction (a) by a competent court . It has long been accepted by the European court that article 5(1) requires a relationship between the detention regime and the purpose of the deprivation of liberty. As the court stated in Ashingdane v United Kingdom (1985) 7 EHRR 528, para 44: More generally, it follows from the very aim of article 5(1) that no detention that is arbitrary can ever be regarded as lawful. The court would further accept that there must be some relationship between the ground of permitted deprivation of liberty relied on and the place and conditions of detention. For example, article 5(1)(d) permits the detention of a minor by lawful order for the purpose of educational supervision. This is understood as implying that the nature of the detention supports the objective of educational supervision. The placement of minors in penal institutions without educational facilities cannot therefore be justified under that provision, except as an interim measure: see, for example, Bouamar v Belgium (1988) 11 EHRR 1. Similarly, article 5(1)(e) permits the lawful detention of persons of unsound mind. The detention of a person as a mental health patient will, however, only be lawful for the purposes of article 5(1)(e) if effected in a hospital, clinic or other appropriate institution: see, for example, Ashingdane v United Kingdom and Brand v Netherlands (2004) 17 BHRC 398. It is to be noted that in the Brand case, in which a violation of article 5(1) was found, the court made a modest award as just satisfaction for the feelings of frustration, uncertainty and anxiety which the applicant must have suffered while detained in a remand centre pending his admission to a custodial clinic. The award was not made on the basis that the applicant should not have been deprived of his liberty. In other words, the court did not treat its finding that the applicants detention in the remand centre had been unlawful as meaning that he had a right under the Convention to immediate release from detention. The requirement that there must be a relationship between the ground of permitted deprivation of liberty relied on and the place and conditions of detention was affirmed by the Grand Chamber in Saadi v United Kingdom (2008) 47 EHRR 17. The case concerned article 5(1)(f), which permits the lawful arrest or detention of a person to prevent his effecting an unauthorised entry into the country or of a person against whom action is being taken with a view to deportation or extradition. The Grand Chamber observed that, where the lawfulness of detention was in issue, compliance with national law was necessary but not sufficient: article 5(1) laid down in addition the requirement that any deprivation of liberty should be in keeping with the purpose of protecting the individual from arbitrariness. It was, it said, a fundamental principle that no detention which was arbitrary could be compatible with article 5(1) (para 67). Key principles had been established on a case by case basis as to what types of conduct on the part of national authorities might constitute arbitrariness for the purposes of article 5(1). One such principle, which the court derived from authorities including Bouamar, was that there must be a relationship between the ground of permitted deprivation of liberty relied on and the place and conditions of detention. In that regard, the Grand Chamber stated: 69. One general principle established in the case law is that detention will be arbitrary where, despite complying with the letter of national law, there has been an element of bad faith or deception on the part of the authorities. The condition that there be no arbitrariness further demands that both the order to detain and the execution of the detention must genuinely conform with the purpose of the restrictions permitted by the relevant sub paragraph of article 5(1). There must in addition be some relationship between the ground of permitted deprivation of liberty relied on and the place and conditions of detention. 70. The notion of arbitrariness in the contexts of sub paras (b), (d) and (e) also includes an assessment whether detention was necessary to achieve the stated aim. The detention of an individual is such a serious measure that it is justified only as a last resort where other, less severe measures have been considered and found to be insufficient to safeguard the individual or public interest which might require that the person concerned be detained. The principle of proportionality further dictates that where detention is to secure the fulfilment of an obligation provided by law, a balance must be struck between the importance in a democratic society of securing the immediate fulfilment of the obligation in question, and the importance of the right to liberty. The duration of the detention is a relevant factor in striking such a balance. 71. The court applies a different approach towards the principle that there should be no arbitrariness in cases of detention under article 5(1)(a), where, in the absence of bad faith or one of the other grounds set out in para 69 above, as long as the detention follows and has a sufficient causal connection with a lawful conviction, the decision to impose a sentence of detention and the length of that sentence are matters for the national authorities rather than for the court under article 5(1). (emphasis added) In that passage, the last sentence of para 69 made it clear that the principle, that there must be some relationship between the ground of permitted deprivation of liberty relied on and the place and conditions of detention, was one which applied to all the sub paragraphs of article 5(1). Paras 70 and 71 explained that there was a difference between article 5(1)(a) and sub paragraphs (b), (d) and (e) in relation to the application of the principle of proportionality, but the first sentence of para 71 confirmed that the general principles set out in para 69 applied to article 5(1)(a). That sentence also made it clear that the existence of a causal connection between the detention and a lawful conviction was not in itself sufficient to ensure compliance with article 5(1)(a). James v United Kingdom In James v United Kingdom (2013) 56 EHRR 12, the court applied the general principle established in Saadi, that article 5(1) requires the conditions of detention to be consistent with the purpose of the detention, to detention sought to be justified under article 5(1)(a). It derived from that principle the conclusion that, after the punishment part or tariff element of an indeterminate sentence for public protection (IPP) has been served and the prisoner remains in detention for reasons of public protection, a real opportunity for rehabilitation should be provided. The case came before the European court after first being considered by the House of Lords: R (Walker) v Secretary of State for Justice [2009] UKHL 22; [2010] 1 AC 553. It concerned IPP prisoners who had been unable to access the courses recommended by the Parole Board. The argument before the House of Lords did not focus on the need for a correlation between the purpose of detention and the conditions of detention. Instead, the argument, and the speeches of Their Lordships, referred to a different strand of the European courts jurisprudence, concerned with the requirement under article 5(1)(a) for detention to be after conviction, which the court had interpreted as meaning that there must be a causal connection between the conviction and the detention. Unsurprisingly, Their Lordships held that such a connection existed in the cases before them, notwithstanding the unavailability of the courses. That being so, it was concluded that there had been no violation of article 5(1)(a). When the case was considered by the European court, it summarised the principles established in its earlier case law under article 5(1)(a) concerning the need for there to be a conviction and for the detention to be after the conviction. It then turned to the stipulation that the detention must be lawful, which meant, first, that the detention must be in compliance with national law, and secondly, that it should be in keeping with the purpose of protecting the individual from arbitrariness (para 191). The court then set out some key principles relating to the types of conduct which might constitute arbitrariness for the purposes of article 5(1), which could be extracted from the courts case law. The third of those was the following (para 194): Thirdly, for a deprivation of liberty not to be arbitrary there must be some relationship between the ground of permitted deprivation of liberty relied on and the place and conditions of detention (see Saadi, para 69). Thus, as noted above, detention for educational supervision pursuant to article 5(1)(d) must take place in a setting and with the resources to meet the necessary educational objectives (see Bouamar, para 50). Where article 5(1)(e) applies, the detention of a person for reasons relating to his mental health should be effected in a hospital, clinic or other appropriate institution (see Aerts v Belgium (1998) 29 EHRR 50, para 46; and Brand, para 62). In the context of article 5(1)(a), a concern may arise in the case of persons who, having served the punishment element of their sentences, are in detention solely because of the risk they pose to the public, if there are no special measures, instruments or institutions in place other than those available to ordinary long term prisoners aimed at reducing the danger they present and at limiting the duration of their detention to what is strictly necessary in order to prevent them from committing further offences (see M v Germany (2009) 51 EHRR 41, para 128; and Grosskopf v Germany (2010) 53 EHRR 7, para 51). The court immediately made it clear (para 194) that the principle that the conditions of detention must reflect its purpose had to be applied realistically and flexibly: However, in assessing whether the place and conditions of detention are appropriate, it would be unrealistic, and too rigid an approach, to expect the authorities to ensure that relevant treatment or facilities be available immediately: for reasons linked to the efficient management of public funds, a certain friction between available and required treatment and facilities is inevitable and must be regarded as acceptable. Accordingly, a reasonable balance must be struck between the competing interests involved. Turning to the facts of the applicants cases, the court agreed with the House of Lords that the need for a causal connection between the convictions and the detention was satisfied (para 199). But there remained the question whether the detention violated article 5(1)(a) by reason of the absence of a genuine correlation between the aim of the detention and the detention itself (para 204). In that regard, the court accepted that one of the purposes of the applicants detention was rehabilitation (para 209). It followed that reasonable opportunities to participate in rehabilitation courses should be made available: As the court has indicated above, in circumstances where a government seeks to rely solely on the risk posed by offenders to the public in order to justify their continued detention, regard must be had to the need to encourage the rehabilitation of those offenders. In the applicants cases, this meant that they were required to be provided with reasonable opportunities to undertake courses aimed at helping them to address their offending behaviour and the risks they posed . While article 5(1) does not impose any absolute requirement for prisoners to have immediate access to all courses they may require, any restrictions or delays encountered as a result of resource considerations must be reasonable in all the circumstances of the case (para 218) The applicants had had little if any access to offending behaviour programmes for substantial periods after their tariffs had expired. Instead, for around two and a half years, they were simply left in local prisons where there were few, if any, offending behaviour programmes (para 220). The inadequate resources which brought about this situation appeared to be the consequence of the introduction of draconian measures for indeterminate detention without the necessary planning and without realistic consideration of the impact of the measures (para 220). In those circumstances, following the expiry of the applicants tariff periods and until steps were taken to progress them through the prison system with a view to providing them with access to appropriate rehabilitative courses, their detention was arbitrary and therefore unlawful within the meaning of article 5(1) of the Convention (para 221). The detention became lawful again, within the meaning of article 5(1), once access to relevant courses was provided (para 244). Two of the applicants also complained of a breach of article 13 of the Convention, which guarantees the right to an effective remedy, on the ground that even if they had succeeded in the domestic courts in their challenge to their detention, they would not have been able to secure their release, because of the relevant statutory provisions. The court examined that complaint under article 5(4), on the basis that it provided a lex specialis in relation to the more general requirements of article 13. Article 5(4) provides: Everyone who is deprived of his liberty by arrest or detention shall be entitled to take proceedings by which the lawfulness of his detention shall be decided speedily by a court and his release ordered if the detention is not lawful. The court observed that lawfulness in article 5(4) had the same meaning as in article 5(1), so that the arrested or detained person was entitled to a review of the lawfulness of his detention in the light not only of domestic law but also of the Convention. The court held that the requirements of article 5(4) were met, notwithstanding that the applicants release could only be ordered by the Parole Board if it concluded that they were no longer dangerous. It reached that conclusion on the basis that the Secretary of States failure to provide access to relevant courses, which rendered their detention unlawful during the periods in which such access was unavailable, could be challenged by proceedings for judicial review. Such proceedings had in fact resulted in the applicants being given access to the relevant courses and assessments. Their release could be ordered by the Parole Board, in accordance with the relevant statutory provisions, if it was satisfied that the individual was no longer dangerous. Thus the combination of the Parole Board and judicial review proceedings could have resulted in an order for their release (paras 231 232). This reasoning is consistent with the courts finding that the detention was unlawful, due to the failure to provide courses, only until steps were taken to progress them through the prison system with a view to providing them with access to appropriate rehabilitative courses (para 221). A judicial remedy was available to ensure that such steps were taken, and thus to bring an end to the unlawful detention. The implication of the reasoning is that the unlawfulness of detention, where it arises from a failure to provide a real opportunity for rehabilitation, does not entitle the prisoner to release, where it can be otherwise addressed. The same approach can be seen in the courts treatment of the award of just satisfaction. The finding of a violation of article 5(1) was not treated as implying that the applicants were entitled under the Convention to immediate release: The basis for the finding of a violation of article 5(1) was that the failure to give timeous access to the relevant courses rendered the applicants detention after the expiry of their tariffs arbitrary. It therefore cannot be assumed that, if the violations in the present cases had not occurred, the applicants would not have been deprived of their liberty. (para 244) The award of just satisfaction was therefore not in respect of a deprivation of liberty, but in respect of the feelings of distress and frustration which continued detention without access to necessary courses must have provoked. The conclusion reached by the court in James in the context of article 5(1)(a) was thus based upon the application of a principle which was established in the case law of the court and had previously been applied in cases falling under article 5(1)(d), (e) and (f): namely, that the conditions of detention must reflect the purpose of the detention, if the detention was to be lawful within the meaning of article 5(1). James decided that it followed that measures aimed at reducing the risk which prisoners present to the public should be in place in circumstances where a government seeks to rely solely on the risk posed by offenders to the public in order to justify their continued detention (para 218, cited at para 12 above). The Grand Chamber rejected the Governments request that James be referred to that chamber. Although the decision went beyond any previous Grand Chamber judgment, the general principle on which it was based had been recognised in Saadi. It was presumably on that basis that it was not considered to raise a serious question affecting the interpretation or application of the Convention or the Protocols thereto, or [a] serious issue of general importance (Rule 73 of the Rules of Court). Subsequent Strasbourg case law The principle established in James was subsequently applied by the European court in a series of cases involving prisoners serving IPP sentences. In each of these cases, as in James itself, the courts decision was based on a careful individual analysis of each applicants prison history. Repeated reference was made to the statement in James that the court must have regard to the detention as a whole (para 201). It was repeatedly stated that, in considering whether a delay in access to required prison courses resulted in a violation of article 5(1), the applicants general progression through the prison system must be assessed in light of the particular circumstances of the case. Examples include Hall v United Kingdom (Application No 24712/12) given 12 November 2013, where there was a post tariff delay of over a year in providing a particular course, but where the applicant had nevertheless been provided with a reasonable opportunity to rehabilitate himself by courses throughout his detention; Dillon v United Kingdom (Application No 32621/11) given 4 November 2014, where a nine month delay between the expiry of the tariff and assessment for a particular course was considered to be not unreasonable having regard to the access to courses which the applicant had previously enjoyed, the continued efforts to ensure his further progress through the prison system, and his overall progression throughout the period of his detention; and Thomas v United Kingdom (Application No 55863/11) given 4 November 2014, where a six month delay in commencing a course was not considered unreasonable having regard both to resource considerations and to the progress that the applicant had already made. A further example, decided after R (Kaiyam) v Secretary of State for Justice, is Alexander v United Kingdom (Application No 54119/10) given 30 June 2015, where there was a post tariff delay of around 14 months in being assessed for a recommended course, and a further delay of about 18 months in obtaining a place, but where prompt steps had nevertheless been taken to begin the applicants progression through the prison system, and he had been given access to a wide range of rehabilitative courses which enabled him to present evidence of risk reduction. The principles which the European court has itself derived from these cases, and others, are discussed at para 33 below. There does not appear to be any case since James in which a complaint under article 5(1) arising from lack of access to courses has succeeded. R (Kaiyam) v Secretary of State for Justice The judgment of the European court in James was considered by this court in R (Kaiyam) v Secretary of State for Justice. The claimants were a life prisoner, named Haney, and three IPP prisoners, named Kaiyam, Massey and Robinson. They argued that the Secretary of States delay in providing them with rehabilitative courses had breached their rights under article 5(1). In a joint judgment with which the other members of the court agreed, Lord Mance and Lord Hughes accepted the European courts conclusion in James that there was an obligation to provide life and IPP prisoners with a real opportunity for rehabilitation. They therefore departed from the decision of the House of Lords in Walker. They declined, however, to accept that the obligation was imposed by article 5(1), as the European court had decided. They were concerned that the European courts reasoning might imply that IPP and life prisoners detained without access to rehabilitation courses were entitled under the Convention to immediate release, and that the statutory regime preventing their release except where recommended by the Parole Board might therefore have to be declared incompatible with Convention rights (para 34). In that regard, they stated: On the reasoning of the European court in James v United Kingdom 56 EHRR 12, failure after the tariff period properly to progress a life or IPP prisoner towards release makes detention during the period of such failure arbitrary and therefore unlawful. If that reasoning be adopted, then such detention is in breach of the express language of article 5(1)(a), and the prisoner should (in the eyes of the European court) be entitled to an immediate order for speedy release under article 5(4). (para 23; emphasis in original) Lord Mance and Lord Hughes responded to that concern by concluding that James went beyond the reasoning in Saadi and did not form part of a clear and constant line of decisions (the case of Ostermnchner v Germany (Application No 36035/04) given 22 March 2012, para 74, which was the closest predecessor, was not cited in Kaiyam, but might have been distinguished in any event). On that basis, following such authorities as Manchester City Council v Pinnock (Secretary of State for Communities and Local Government intervening) [2010] UKSC 45; [2011] 2 AC 104, para 48, they considered that domestic courts need not adopt the analysis in James. Instead, they treated the duty to facilitate the progress of prisoners subject to life and IPP sentences towards release as being implied as an ancillary duty in the overall scheme of article 5 as a whole. They considered that the ancillary duty existed throughout the prisoners detention (para 48), rather than being confined to the post tariff period, as the European court had held in James, in accordance with the logic of its reasoning. As explained above, however, far from holding that the prisoner was entitled under article 5(4) to an immediate order for speedy release, the European court held in James that article 5(4) was satisfied by (1) the availability of judicial review to challenge the failure to provide the relevant courses, and (2) the ability of the Parole Board to order release under the statutory provisions once satisfied that the individual was no longer dangerous. The logic of the European courts approach was that an obligation to bring an end to unlawful detention can be met by bringing an end to the factor which renders the detention unlawful. No reference was however made to that part of the James judgment in Kaiyam. As explained at para 15 above, the European courts treatment in James of the claims for just satisfaction also confirmed that unlawfulness under article 5(1) arising from a failure to provide courses did not entail an obligation under the Convention to secure the applicants immediate release. Lord Mances and Lord Hughess concern was exacerbated by a passage in the James judgment in which the European court, when considering whether there had been a violation of article 5(1), referred to an argument advanced on behalf of the Government: The court acknowledges that the IPP sentence was intended to keep in detention those perceived to be dangerous until they could show that they were no longer dangerous. The Government has suggested that, in these circumstances, a finding of a violation of article 5(1) as a result of the lack of access to appropriate treatment courses would allow the release of dangerous offenders who had not yet addressed their risk factors. The court accepts that where an indeterminate sentence has been imposed on an individual who was considered by the sentencing court to pose a significant risk to the public at large, it would be regrettable if his release were ordered before that risk could be reduced to a safe level. However, this does not appear to be the case here. (para 217) It is not clear from the James judgment what exactly the Governments argument was, to which para 217 was directed, but given the European courts conclusion that the violation of article 5(1) did not entitle the prisoners to immediate release, it presumably understood the argument to concern the position under domestic law. Applying the courts reasoning as to the position under article 5(4) of the Convention, however, there cannot in ordinary circumstances be a right to immediate release under domestic law. As the court explained, where detention is in violation of article 5(1) by reason of a failure to provide a real opportunity for rehabilitation, an appropriate remedy is provided by an order requiring such an opportunity to be provided, with monetary compensation for the absence of the opportunity in appropriate cases. As the court has also made clear, however, the threshold for establishing a violation of article 5(1) on this basis is a high one: see paras 11 and 21 above, and para 34 below. It is essential to bear in mind the realism and flexibility of the European courts approach. As Lord Mance and Lord Hughes noted, failings in the prison system which arise due to a lack of resources and facilities cannot always be redressed at the drop of a hat, whatever order a court may make. As explained in para 21 above, however, the court said in terms in James that it would be unrealistic, and too rigid an approach, to expect the authorities to ensure that relevant treatment or facilities were made available immediately. Its decision under article 5(4) confirmed that approach: the court focused upon the prompt transfer of the applicants to prisons where the necessary courses were available, rather than on the time which subsequently passed before places on the courses were provided (which, in the case of the applicant Lee, was significant). The high threshold for establishing a violation of article 5 on this basis was also emphasised by Lord Mance and Lord Hughes. As they observed at para 60, article 5 does not create an obligation to maximise the coursework or other provision made to the prisoner, nor does it entitle the court to substitute, with hindsight, its own view of the quality of the management of a prisoner and to characterise as arbitrary detention any case which it concludes might have been better managed. It requires that an opportunity must be afforded to the prisoner which is reasonable in all the circumstances, taking into account, among all those circumstances, his history and prognosis, the risks he presents, the competing needs of other prisoners, the resources available and the use which has been made of such rehabilitative opportunity as there has been. On the facts of the claimants cases, Lord Mance and Lord Hughes considered that the ancillary duty (which, as explained above, they considered to apply throughout the prisoners detention) had been breached in the cases of two of the claimants. In the case of Mr Haney, the life prisoner, there had been a delay of about a year, prior to the expiry of his tariff, in transferring him to an open prison after the Secretary of State had issued a letter indicating that that was appropriate. The court posed the question, was Haney afforded a reasonable opportunity to reform himself and . to demonstrate that he no longer presented an unacceptable risk to the public, and stated that the answer to this question is . given by the letter to him from the Secretary of State (paras 48 49). On the view that by this letter the Secretary of State identified what a reasonable opportunity was for Haney to demonstrate that he was no longer a danger . and adjudged that he should have that opportunity there and then (para 49), there was held to have been a violation of the ancillary obligation, prior to the expiry of the tariff. In the case of Mr Massey, one of the IPP prisoners, a timetable for his progress had been provided by the Secretary of State in a letter, but had not been adhered to. In the view of the court, the letter effectively defined what was regarded as a reasonable opportunity for Massey to build on the partial progress which he had made and to demonstrate (if he could) that he was safe to release (para 69). Given the failure to adhere to the timetable, there was a failure to provide him with the opportunity to try to demonstrate that he was safe for release which the Secretary of State regarded as reasonable (ibid), and therefore a breach of the ancillary obligation. The court was divided in the case of a third claimant, Mr Robinson, the majority concluding that there had been no violation. Kaiyam v United Kingdom The three IPP prisoners subsequently presented applications to the European court, complaining of violations of article 5(1). Their complaints were all rejected as manifestly unfounded: (2016) 62 EHRR SE13 (there is an unfortunate misprint in the report of the decision at para 84: Mr Masseys application was not held to be admissible, but inadmissible). The European court thus found that the complaint made by Mr Massey of a violation of article 5, which this court had upheld, was manifestly unfounded. The same conclusion was reached in relation to Mr Robinsons complaint. It is clear from the European courts reasoning that Mr Haneys complaint relating to a pre tariff delay, which this court had upheld, would also have been rejected. As the European court explained, it had been held in James that a real opportunity for rehabilitation was a necessary element of any part of the detention which was to be justified solely by reference to public protection. It follows, the court stated, that, strictly speaking, article 5(1)(a) does not require a real opportunity for rehabilitation during the tariff period itself, since this represents the punishment part of the sentence (para 67). The court provided a valuable summary of its reasoning in James and in the subsequent case law: 69. In examining whether part of an applicants detention post tariff was unjustified for the purposes of article 5(1)(a) of the Convention, regard must be had to the detention as a whole (see James at para 201). Thus, where, as in the present applications, the applicant claims that delay in his access to prison courses constituted a violation of article 5(1)(a), the applicants general progression through the prison system is to be assessed in light of the particular circumstances of the case (see Hall v United Kingdom at para 32; Black v United Kingdom (Application No 23543/11) 1 July 2014 at para 54; Thomas v United Kingdom at para 49; and Taylor v United Kingdom (Application No 2963/12) 3 March 2015 at para 39). Such assessment should include consideration of whether, and to what extent, the applicant was provided with an opportunity to progress even before the expiry of his tariff (see, for an example of the courts approach, James at paras 211, 213 215 and 219 220). 70. It is clear from the courts case law in this area that cases in which it is prepared to find that a period of post tariff detention has failed to comply with the requirements of article 5(1)(a) on account of a delay in access to rehabilitative courses will be rare. In particular, it is not for this court to second guess the decisions of the qualified national authorities as regards the appropriate sentence plan (see Dillon v United Kingdom at para 50; and Alexander v United Kingdom at para 47). Neither is it the courts role to impose a particular timetable on the authorities. Any delays encountered in the provision of specific courses must be assessed in the context of the gravity of the offence and the amount of offending behaviour work therefore required, and against the backdrop of the range of rehabilitative courses already accessed by the applicant (see Alexander at para 46). In finding a violation in the case of James, the court drew attention to the fact that substantial periods of time passed in respect of each applicant before they even began to make any progress in their sentences (at para 220). They had therefore not been afforded reasonable opportunities to undertake courses aimed at helping them address their offending behaviour. The European court declined to adopt this courts analysis of an ancillary duty and adhered to the reasoning in James. It made clear the high threshold imposed by its test of arbitrariness and hence unlawfulness, and explained why it attached less significance to the Secretary of States letter to Mr Massey than this court had done: 71. In finding a breach of that ancillary duty in Mr Masseys case, the Supreme Court referred solely to the failure to provide him with the opportunity which the Secretary of State had regarded as reasonable in his letter of October 2010 to try to demonstrate that he was safe for release. The nature and extent of the delay in affording Mr Massey access to the ESOTP was in and of itself sufficient to give rise to a violation of the ancillary duty. 72. It is not the role of this court to determine in the abstract whether the UK has properly implemented the judgment in James within its domestic legal order. This is primarily a matter for the Committee of Ministers in the exercise of its jurisdiction under article 46(2) of the Convention. This courts role is confined to determining whether delays in the provision of rehabilitative courses to the present applicants were such as to introduce a degree of disproportionality leading to arbitrariness, as understood by James, and thus rendering the relevant periods of detention unlawful within the meaning of article 5(1)(a) of the Convention. In making this assessment, this court cannot examine specific periods of delay in a vacuum: it must view any period of delay in the light of the detention as a whole and the specific factors identified in its case law. The fact that a delay occurred, even where that delay was at odds with what the Secretary of State had indicated as a reasonable opportunity to try and demonstrate safety for release, is not sufficient to meet the threshold required for the establishment of arbitrariness in breach of article 5(1)(a) of the Convention under James. In this sense, the test applied by this court to whether a violation of article 5(1)(a) has been made out in cases concerning delayed access to rehabilitative courses might be said to be more stringent than the approach applied by the Supreme Court to whether a breach of the ancillary duty which it read into article 5 to facilitate the progress of IPP prisoners towards release by appropriate courses and facilities has been demonstrated. (footnotes omitted) In its consideration of the facts of the applicants cases, the court found that, in the cases of Mr Kaiyam and Mr Robinson, prompt steps were taken to begin their progression through the prison system well before the expiry of their tariffs. A real opportunity for rehabilitation was provided to them, through the provision of reasonable opportunities to undertake courses aimed at helping them to address their offending behaviour. There was therefore no appearance of a violation of article 5(1). In the case of Mr Massey, he had to wait 18 months post tariff to begin a course, and was not provided with access to any other courses during that time. There was no doubt that the delay was significant, given the practical importance of completion of the course for his ability to satisfy the Parole Board that he was safe to be released. The question, however, was whether, in the light of his detention as a whole, the delay was of such a degree as to render that period of his detention arbitrary and thus unlawful. That period of inactivity had therefore to be put in context. In the space of five years detention, Mr Massey had completed four courses aimed at tackling the reasons for his offending. He had made significant progress in his sentence and had been afforded multiple opportunities to present to the Parole Board evidence of his work in reducing his risk. Against that backdrop, the delay in access to the course could not be said to have deprived Mr Massey of a real opportunity for rehabilitation through the provision of reasonable opportunities to undertake courses aimed at helping him to address his offending behaviour. There was therefore no appearance of a violation of article 5(1). Murray v Netherlands Finally, in this survey of the evolution of the Strasbourg case law, it is necessary to note the judgment of the Grand Chamber in Murray v The Netherlands (2016) 64 EHRR 3. The case concerned a mentally disordered prisoner serving a life sentence, who had been detained for 19 years in an ordinary prison without access to medical treatment. His complaint was brought under article 3 of the Convention, which prohibits inhuman or degrading treatment. In the course of its judgment, the Grand Chamber cited the judgment in James: 102. The court observes that the principle of rehabilitation, that is, the reintegration into society of a convicted person, is reflected in international norms (see paras 70 76 above) and has not only been recognised but has over time also gained increasing importance in the courts case law under various provisions of the Convention (see, apart from Vinter v United Kingdom [GC] (2016) 63 EHRR 1, for instance Mastromatteo v Italy [GC], Reports of Decisions and Judgments 2002 VIII, para 72; Dickson v the United Kingdom [GC], (2008) 46 EHRR 41, para 28; James, Wells and Lee v United Kingdom, para 209; and Khoroshenko v Russia [GC] (Application No 41418/04) given 30 June 2015, paras 121 and 144 145). In a slightly different context the court has, moreover, held that, in circumstances where a Government seek to rely solely on the risk posed by offenders to the public in order to justify their continued detention, regard must be had to the need to encourage the rehabilitation of those offenders (James, Wells and Lee, para 218). 103. Notwithstanding the fact that the Convention does not guarantee, as such, a right to rehabilitation, the courts case law thus presupposes that convicted persons, including life prisoners, should be allowed to rehabilitate themselves. Indeed, the court has held that . a whole life prisoner is entitled to know . what he or she must do to be considered for release and under what conditions (Vinter, cited above, para 122). It has also held, with reference to Vinter, that national authorities must give life prisoners a real opportunity to rehabilitate themselves (see Harakchiev and Tolumov (Application Nos 15018/11 and 61199/12) given 8 July 2014, para 264). It follows from this that a life prisoner must be realistically enabled, to the extent possible within the constraints of the prison context, to make such progress towards rehabilitation that it offers him or her the hope of one day being eligible for parole or conditional release. This could be achieved, for example, by setting up and periodically reviewing an individualised programme that will encourage the sentenced prisoner to develop himself or herself to be able to lead a responsible and crime free life. Para 218 of the James judgment, which the Grand Chamber cited at para 102, was quoted at para 12 above. In it, the court derived the obligation to encourage rehabilitation from article 5(1). The Grand Chamber referred again to the cases cited at para 102 of its Murray judgment in Hutchinson v United Kingdom (Application No 57592/08) given 17 January 2017, para 43. Should this court align its approach with that of the European court? It is apparent from this survey of the Strasbourg case law that the approach adopted by the European court in James has been applied by the court in a substantial number of subsequent cases, and has been cited by the Grand Chamber with apparent approval. The question arises whether this court should now follow its reasoning, and depart from the position which it adopted in Kaiyam, on the basis that it is no longer possible to deny that the analysis in James forms part of a clear and constant line of decisions. The question would be of limited importance if the issue was merely one of taxonomy: whether the relevant obligation arises under article 5(1) or is immanent in article 5 considered as a whole. But the issue goes beyond that: it also affects the substance of the obligation. In the first place, as explained earlier, in Kaiyam this court treated the ancillary obligation which it found to be implicit in article 5 as one which applied, in addition to obligations arising under the common law, throughout the prisoners detention (para 24 above). Indeed, Mr Haneys application, which succeeded, was brought almost a year before his tariff expired. The European court, on the other hand, regards the issue of lawfulness as arising only after the tariff or punishment part of an IPP sentence has expired, although earlier measures to encourage the prisoners rehabilitation will form part of the relevant circumstances (paras 32 33 above). In that regard, the European courts approach reflects the logic of locating the obligation in article 5(1)(a): it is only after the tariff has expired that any question can arise whether the continued detention is arbitrary, and therefore not lawful within the meaning of article 5(1)(a). Secondly, in Kaiyam this court treated the ancillary obligation as being to afford the prisoner a reasonable opportunity to rehabilitate himself and to demonstrate that he is no longer a risk to the public. The relevant standard was one of reasonableness, not arbitrariness. The court concluded that that standard had not been met in two of the cases before it. More recently, the Court of Appeal has expressed the view that the apparent theoretical difference between this standard and the common law standard of Wednesbury unreasonableness is unlikely to lead to different outcomes in many, if any, cases: R (Weddle) v Secretary of State for Justice [2016] EWCA Civ 38, para 50 (a case decided before the prisoners tariff had expired). The expression reasonable opportunities was also used by the European court in James, but in a context where the legal issue was whether the detention was arbitrary and therefore unlawful within the meaning of article 5(1) (paras 10 and 13 above). As the outcome of the applications to the European court in Kaiyam v United Kingdom makes clear, and as that court itself noted (para 34 above), this is a more stringent standard. The stringency of the standard applied is thus derived from the language of article 5(1)(a). Thirdly, in Kaiyam this court treated the Secretary of States own assessment of what was reasonable, in the cases of Mr Haney and Mr Massey, as conclusive of the question whether the ancillary obligation had been fulfilled (para 34 above). As the European court made clear in its own judgment in Kaiyam, its approach is more stringent: the fact that a delay occurred, even where that delay was at odds with what the Secretary of State had indicated as a reasonable opportunity to try and demonstrate safety for release, is not sufficient to meet the threshold required for the establishment of arbitrariness in breach of article 5(1)(a) (see para 34 above). In all these respects, this courts reluctance to accept that the relevant obligation derives from article 5(1)(a) has resulted in the imposition on the prison authorities of a duty which is significantly different from, and more demanding than, the duty imposed by the Convention. That is a notable departure from the usual situation in which domestic and Strasbourg jurisprudence march hand in hand. What, then, of this courts fundamental reason for declining to follow the reasoning of the European court in James: that, if the obligation were located in article 5(1), its violation might entitle the prisoner under the Convention to immediate release? In considering that concern, it has to be borne in mind in the first place that, as later Strasbourg cases have made clear, the threshold for finding a violation of the obligation imposed by article 5(1)(a) is higher than this court considered it to be in Kaiyam. More fundamentally, as explained in paras 14 16 and 25 above, the European court held in James that the requirement under article 5(4), that a persons release should be ordered if his detention was not lawful, was satisfied by the availability of remedies (1) to bring an end to the aspect of the detention which rendered it unlawful within the meaning of article 5(1)(a), namely the failure to provide an opportunity for the prisoner to rehabilitate himself, and (2) to enable the prisoner to secure his release if the Parole Board was satisfied that he was no longer dangerous. No reference was made to this aspect of the judgment in James by this court in Kaiyam. The European courts treatment of the claims for just satisfaction in James also confirmed that unlawfulness under article 5(1) arising from a failure to provide courses did not entail an obligation under the Convention to secure the applicants immediate release. In this unsatisfactory situation, it is necessary for this court to confront squarely the difficulties arising from its reasoning in Kaiyam. The appropriate course is for this court now to adopt the same approach to the interpretation of article 5(1)(a) as has been followed by the European court since the case of James, and cease to treat the obligation in question as an ancillary obligation implicit in article 5 as a whole. Emphasis should however be placed on the high threshold which has to be surmounted in order to establish a violation of the obligation. As the European court stated in Kaiyam at para 70, cases in which a violation is found will be rare (see para 33 above). That is consistent with the statement in R (Sturnham) v Parole Board (No 1) [2013] UKSC 23; [2013] 2 AC 254, para 13, that a violation of article 5(1) of the Convention . would require exceptional circumstances warranting the conclusion that the prisoners continued detention had become arbitrary. The guidance given by the European court, for example at paras 69 70 of Kaiyam, as well as that given in the present judgment, should be borne in mind. Extended sentences All the cases so far discussed in which this court, or the European court, has found there to be an obligation to provide an opportunity for rehabilitation have concerned life or IPP sentences. They can be contrasted with cases concerned with ordinary determinate sentences of imprisonment, in which both the European court and this court have treated the sentence as in itself rendering the detention lawful for the duration of the sentence period: see, for example, R (Whiston) v Secretary of State for Justice [2014] UKSC 39; [2015] AC 176, and the cases cited there. The question which arises in the present appeal is whether, and if so how, the obligation to provide an opportunity for rehabilitation applies to a prisoner sentenced to an extended sentence. The power to impose an extended sentence was introduced by the Crime and Disorder Act 1998 (the 1998 Act). Section 58 conferred the power to impose an extended sentence on courts in England and Wales (corresponding provisions are currently contained in sections 226A and 226B of the Criminal Justice Act 2003, as inserted by section 124 of the Legal Aid, Sentencing and Punishment of Offenders Act 2012). In relation to Scotland, section 86(1) of the 1998 Act inserted section 210A of the Criminal Procedure (Scotland) Act 1995 (the 1995 Act). That provision forms part of a body of law which is highly complex and has been subject to frequent change. I shall confine myself to the provisions which are directly relevant to this appeal, as in force at the material time. So far as relevant, section 210A provides: (a) (1) Where a person is convicted on indictment of a sexual or violent offence, the court may, if it intends, in relation to (i) sentence of imprisonment; or (ii) a violent offence, to pass such a sentence for a term of four years or more; and a sexual offence, to pass a determinate (b) considers that the period (if any) for which the offender would, apart from this section, be subject to a licence would not be adequate for the purpose of protecting the public from serious harm from the offender, pass an extended sentence on the offender. (2) An extended sentence is a sentence of imprisonment which is the aggregate of (a) the term of imprisonment (the custodial term) which the court would have passed on the offender otherwise than by virtue of this section; and a further period (the extension period) for (b) which the offender is to be subject to a licence and which is, subject to the provisions of this section, of such length as the court considers necessary for the purpose mentioned in subsection (1)(b) above. (3) The extension period shall not exceed . ten years. (5) The term of an extended sentence passed for a statutory offence shall not exceed the maximum term of imprisonment provided for in the statute in respect of that offence. It follows from section 210A that an extended sentence comprises, in the first place, a custodial term, which is the term of imprisonment which the court would have imposed if section 210A did not exist, and in addition an extension period for which the offender is to be on licence beyond the period during which he would have been on licence if section 210A did not exist. Both periods are fixed by the court. They cannot total more than the maximum sentence available, and the extension period cannot exceed ten years. In fixing the custodial term, as in fixing an ordinary sentence of imprisonment, the court will take account of all matters relevant to sentencing and have regard to all the accepted objectives of a custodial sentence, including punishment, deterrence, public protection and rehabilitation. The reason for imposing an extended sentence is that the period for which the offender would have been subject to a licence under early release provisions, if he had received an ordinary sentence of imprisonment equal in length to the custodial term, is considered by the court to be insufficient for the protection of the public. The circumstances must also be such as do not require or justify the imposition of a sentence of life imprisonment or an order for lifelong restriction. Release on licence is intended to ensure that the process of transition from custody to freedom is supervised, so as to maximise the chances of the ex prisoners successful reintegration into the community and minimise the chances of his relapse into criminal activity. The licence is accordingly subject to conditions designed to assist in achieving those objectives, which normally place the ex prisoner under supervision and require him to comply with the instructions of his supervising officer. The licence can be revoked, and the ex prisoner recalled to custody, in the event that he breaches the conditions of his licence. The statutory provisions governing early release, set out in Part 1 of the Prisoners and Criminal Proceedings (Scotland) Act 1993 (the 1993 Act), apply in relation to extended sentences as if any reference to a sentence or term of imprisonment was a reference to the custodial term of an extended sentence: section 26A(2), inserted by section 87 of the Crime and Disorder Act 1998. Those provisions have also been the subject of frequent amendment. For present purposes, it is necessary only to consider the provisions which are relevant to this appeal, as in force at the relevant time. Under those provisions, a prisoner, such as the appellant, whose custodial term is of four years or more is entitled under section 1(2) to be released on licence after serving two thirds of the custodial term (a different regime applies to prisoners who were sentenced after 1 February 2016, under section 1(2A) of the 1993 Act, inserted by section 1(2)(b) of the Prisoners (Control of Release) (Scotland) Act 2015). He is also eligible for release on licence, on the recommendation of the Parole Board for Scotland (the Board), after serving one half of the custodial term: section 1(3). When he is released on licence, the licence remains in force until the end of the extension period, unless revoked under section 17: section 26A(3). The court which fixes the custodial term of an extended sentence is, of course, aware of the statutory provisions governing early release. But those provisions do not influence the length of the custodial term. The court does not, for example, impose a custodial term of six years because it judges four years to be the appropriate period in custody. The provisions governing early release are, however, relevant to the imposition of an extended sentence. As explained earlier, in terms of section 210A of the 1995 Act it is only where the period (if any) for which the offender would, apart from this section, be subject to a licence would not be adequate for the purpose of protecting the public from serious harm from the offender that an extended sentence can be imposed. The court therefore has to consider the period for which the offender would be on licence under early release provisions, and therefore subject to supervision with the possibility of being recalled to custody, if an ordinary sentence of imprisonment were imposed, and assess whether that period would be adequate to protect the public from serious harm. If not, the court can ensure that the offender is on licence for a further period, fixed as the extension period. Under section 17(1) of the 1993 Act, substituted by section 36(4) of the Criminal Justice (Scotland) Act 2003, the Scottish Ministers are empowered to revoke a licence and recall the prisoner to prison if recommended to do so by the Board, or if it is in their opinion expedient in the public interest and it is not practicable to await the recommendation of the Board. On the revocation of the licence, the prisoner is liable to be detained in pursuance of his sentence: section 17(5). Under section 17(3), also substituted by section 36(4) of the 2003 Act, the Scottish Ministers must refer the case of a person whose licence is revoked to the Board. Under section 3A(4), on a reference under section 17(3) the Board must, if it is satisfied that it is no longer necessary for the protection of the public from serious harm that the prisoner should be confined (but not otherwise), direct that he should be released. If such a direction is given, the Scottish Ministers must release the prisoner on licence: section 3A(5). Section 3A(2) provides for the review by the Board of the cases of prisoners serving extended sentences whose licences have been revoked, at not less than annual intervals. Section 3A(4) and (5), inserted by section 88 of the Crime and Disorder Act 1998, apply to such a review. Under section 16 of the 1993 Act, read with section 26A(11), where a prisoner serving an extended sentence is released on licence and then commits another offence punishable by imprisonment prior to the expiry of the sentence, the court which imposed the extended sentence may order him to be returned to prison for the whole or any part of a period equal in length to the period between the date when the new offence was committed and the date when the extended sentence would have expired. The period ordered to be served is taken to be a sentence of imprisonment for the purposes of the 1993 Act (section 16(5)), and is therefore subject to the early release provisions. Article 5(1) and extended sentences As was emphasised by counsel for the Board, the Scottish Ministers, and the Advocate General for Scotland, the previous cases in which the European Court and this court have applied the principle established in James have all concerned life or IPP sentences. That does not, however, imply that the principle is necessarily confined to sentences of that kind. When the question arises whether the principle applies to a different type of sentence, it is necessary to consider whether the differences are such as to lead to a different result. In that regard, counsel emphasised that an extended sentence is determinate, in the sense that the court fixes the length of the extension period. That was argued to be a critical difference. Counsel for the appellant, on the other hand, emphasised that the court does not impose any period of imprisonment to be served once the custodial term has passed: the duration of any detention during the extension period depends, as in life and IPP cases, on decisions made by the executive and the Board. The Advocate General also laid emphasis on the fact that section 210A(2) of the 1995 Act refers to the aggregate of the custodial term and the extension period as a sentence of imprisonment. As Lord Hope of Craighead remarked, however, in R (Giles) v Parole Board [2003] UKHL 42; [2004] 1 AC 1, para 37, the approach which the European court adopts is to look beyond the appearances and the language used and concentrate on the realities of the situation. Attention therefore needs to be focused on the practical effect of such a sentence. Prisoners who are detained during the custodial term, or during a period ordered to be served under section 16 of the 1993 Act (as explained in para 55 above), are during that period in an analogous position to prisoners serving determinate sentences. They are serving a period of imprisonment of a term of years which the court has stipulated as appropriate for the offence committed. If they are released on licence and then recalled during that period, they continue to serve the period of imprisonment imposed by the court. It follows, according to the Strasbourg jurisprudence relating to determinate sentences, and the majority view in Whiston, that the order of the court imposing that period of imprisonment is sufficient to render their detention during the custodial term lawful for the purposes of article 5(1)(a), and the judicial supervision required by article 5(4) is incorporated in the original sentence. Prisoners who are detained during the extension period, other than by virtue of an order made under section 16 or another sentence, are in a different position in three closely related respects. First, no court has ordered that the prisoner should be detained during that period. Rather, the court has ordered that he should be subject to compulsory supervision in the community during that period. The court has therefore taken the view that, prima facie, the risk to the public can be satisfactorily managed in the community by means of that supervision (otherwise another type of sentence would have been imposed). But in the event that the supervision arrangements break down or fail to achieve their objective, the order has the consequence, under the relevant statutory provisions, that the person is subject to detention if (1) his licence is revoked by the Scottish Ministers and (2) the Board is not satisfied that it is no longer necessary for the protection of the public from serious harm that he should be confined. It follows that if the licence is revoked, the prisoner is not being recalled to serve a period of imprisonment imposed by the court. Whether he is detained, and the duration of any such detention, are determined by the Scottish Ministers and the Board. The fact that the court has set a limit to the extension period does not alter that analysis (see, for example, Van Droogenbroeck v Belgium (1982) 4 EHRR 443, and the discussion of that case in R (Giles) v Parole Board, para 37). Secondly, the purpose of detention during the extension period is materially different from that of a determinate sentence. In terms of section 210A(2)(b) of the 1995 Act, the extension period is of such length as the court considers necessary for the purpose mentioned in subsection (1)(b), namely protecting the public from serious harm from the offender: see para 48 above. The punitive aspect of the sentence has already been dealt with by the custodial term, which is the term of imprisonment . which the court would have passed on the offender otherwise than by virtue of this section: section 210A(2)(a). Where a prisoner serving an extended sentence is detained during the extension period, other than by virtue of an order made under section 16 or another sentence, his continued detention is therefore justified solely by the need to protect the public from serious harm. In terms of section 3A(4) of the 1993 Act, he will be released, following his recall by the Scottish Ministers, only if the Board is satisfied that it is no longer necessary for the protection of the public from serious harm that the prisoner should be confined. Thirdly, the fact that the prisoners detention during the extension period has not been ordered by a court, but depends on recall by the Scottish Ministers, means that it must be supervised by a judicial body. That consequence also flows from the fact that the lawfulness of detention during the extension period, for the purposes of article 5(1)(a) of the Convention, depends on whether or not the prisoner ceases to present a risk to the public of serious harm. That is not a matter which was determined by the original sentence of the court. It depends on factors which are susceptible to change with the passage of time, namely mental instability and dangerousness: Mansell v United Kingdom (Application No 32072/96) given 2 July 1997 and Thynne, Wilson and Gunnell v United Kingdom (1990) 13 EHRR 666, para 70. Judicial supervision of detention during the extension period is therefore necessary under article 5(4) of the Convention: see the principles set out in R (Giles) v Parole Board, paras 40 41, which were applied to extended sentences in R (Sim) v Parole Board [2003] EWCA Civ 1845; [2004] QB 1288. The requirement of judicial supervision is met by the provision made by sections 3A(2) and 17(3) of the 1993 Act for reviews by the Board (explained in para 54 above). Since that system of periodical reviews is predicated on the possibility that prisoners may be reformed, the provision of a real opportunity for rehabilitation forms a necessary element of detention during that period. Having regard to these circumstances the indefinite (albeit not unlimited) duration of detention during the extension period, its preventive purpose, and the possibility of change in response to opportunities for rehabilitation the reasoning which led the European court to decide in James, in the context of IPP sentences, that article 5(1)(a) imposed an obligation to provide the prisoner with a real opportunity for rehabilitation is equally applicable. As was explained earlier, the reasoning in James was based on the need for the conditions of detention to be related to the purpose of the detention, in order to avoid arbitrariness and hence unlawfulness within the meaning of article 5(1)(a). The critical feature of IPP sentences, after the prisoners had served the punishment element of their sentences, was that they were in detention solely because of the risk they pose to the public (para 194, cited at para 10 above). It followed that there must be measures in place aimed at reducing the danger they present and at limiting the duration of their detention to what is strictly necessary in order to prevent them from committing further offences (ibid). That reasoning applies equally to prisoners detained during the extension period of an extended sentence, other than by virtue of a section 16 order or a concurrent sentence. The same rationale is apparent in the courts statement in James that in circumstances where a government seeks to rely solely on the risk posed by offenders to the public in order to justify their continued detention, regard must be had to the need to encourage the rehabilitation of those offenders (para 218, cited at para 12 above). That statement was repeated by the Grand Chamber in Murray v The Netherlands (para 102, cited at para 37 above). The situation of a prisoner who is detained during the extension period of an extended sentence is an example of such circumstances. under article 5(1)(a). The facts of the present case On 5 January 2006 the appellant was convicted at the High Court at Edinburgh of culpable homicide, after fatally stabbing another youth in the heart with a flick knife. He received an extended sentence of ten years imprisonment, of which the custodial term was seven years and the extension period was three years. The sentence was backdated to 3 August 2005. The appellant was initially held at HMYOI Polmont, a unit for young offenders. He undertook rehabilitative course work provided there. During 2006 he completed the Anger Management programme. During 2007 he completed the Constructs course (a programme designed for persistent offenders, with a focus on addressing poor problem solving skills). He was assessed as unsuitable for the Violence Prevention programme. In September 2008 he was transferred to HMP Friarton, a national top end facility for long term prisoners (national top end being the half way point between closed and open conditions). In December 2008 It is necessary next to consider the present case in the light of the obligation he was considered by the Board for release at the halfway point in his custodial term. It decided against his release. It noted that he had incurred numerous misconduct reports, including for fighting and assaults. The risk of his reoffending was assessed as medium, following his completion of the programmes, but the risk of his potential for causing serious harm should he reoffend remained high. In January 2009 the appellant was returned to closed conditions at HMYOI Polmont following a number of positive drugs tests. During 2009 he completed an Alcohol Awareness course and a First Steps Drug Awareness course. In October 2009 he was transferred to HMP Edinburgh, as he was then over 21. On 1 April 2010 he was released on licence, having served two thirds of his custodial term. On 18 August 2010 the appellant stole a car while under the influence of alcohol. His plea of guilty to a charge of the theft, and of not guilty to several other charges, was accepted on 26 August 2010. On 7 September 2010 he appeared in the High Court pursuant to section 16 of the 1993 Act (explained in para 55 above). In the event, no order was made. On 28 September 2010 the Board decided that he should be recalled to custody. His licence was then revoked by the Scottish Ministers, and he returned to custody at HMP Edinburgh on 30 September 2010. On 21 October 2010 he was sentenced at the Sheriff Court to 40 days imprisonment in respect of the new offence, to run concurrently with his extended sentence. His case was also referred to the Board in accordance with section 17(3) of the 1993 Act (explained in para 54 above). During November 2010 the appellant was involved in a serious assault on another prisoner (he was subsequently found guilty of the assault). He refused to attend a case management conference held in anticipation of the hearing before the Board. He was also not engaging with an organisation which provided drugs and alcohol courses. The case conference regarded it as highly concerning that he had incurred numerous misconduct reports prior to his release on licence, despite having completed the Constructs course and the Anger Management programme. The Board reviewed his case on 8 December 2010 and decided that it was necessary for the protection of the public from serious harm that he should continue to be confined. In the Boards view, he remained a high risk of reoffending and of causing harm to others, and the risk he posed could not be managed in the community. The Board advised that he should be assessed for his suitability to repeat the Constructs course and to undertake the Violence Prevention programme. The appellant was listed for assessment for the Constructs course and the Violence Prevention programme, which were available at the prison where he was then located. In June 2011, prior to the assessment being carried out, he was transferred to HMP Addiewell, where the Violence Prevention programme was not available, following a fight with another prisoner. During August and September 2011 he undertook an Alcohol Awareness course. During November 2011 he completed the Goals course (concerned with pro social behaviour). On 6 December 2011 the Board again reviewed his case and decided not to direct his release. It noted that since his recall he had been the subject of several misconduct reports, including three assaults. He had also been the subject of a number of intelligence entries relating to violence, which he denied. He had failed to demonstrate that he could comply with the prison routine. He was not currently engaging with the organisation which offered drug and alcohol programmes, despite the role of excessive drinking in his offending history. He continued to be assessed as presenting a high risk of reoffending and of causing harm. He required to progress to the open estate to allow him to demonstrate his ability to adhere to licence conditions and gradually reintegrate into the community. Transfer to open conditions was however dependent on re classification as a low risk prisoner. In January 2012 the appellant was found guilty of another assault. In February 2012 he underwent the Generic Programme Assessment, the purpose of which was to assess which courses would be appropriate for him. Following that assessment, the Programme Case Management Board decided in May 2012 that he should repeat the Constructs course and then undertake the CARE programme (Controlling Anger and Regulating Emotion). On 4 August 2012 his custodial term ended, and the extension period began. It is said on his behalf that he was informed about that time that there were 60 prisoners at HMP Addiewell awaiting placement on the Constructs course and the CARE programme, and that the prison had the capacity to run two such courses every nine weeks, each course taking ten prisoners at a time. Places were allocated in accordance with a waiting list prepared in accordance with a national policy which prioritised prisoners according to the earliest date when they might be eligible for release. Given his position on the waiting list, he was expected to begin the Constructs course in November 2012. In the event, the course due to begin in November was postponed as a result of changes in the intervention team who provided courses at the prison. On 6 December 2012 the Board again reviewed his case, and decided that he should remain in custody and progress in terms of his management plan, which envisaged his progression towards a transfer to open conditions following the completion of course work and a sustained period of good behaviour. It noted that little progress had been made, partly because he had been unable to undertake the programme work planned for him, but also because he had incurred five misconduct reports during 2012, including one for assault, which would have been taken into account in considering his suitability to progress. The responsibility for that lay with him. The Board encouraged him to engage with the management plan for his sentence and to demonstrate and maintain good behaviour, without adverse reports, for a sustained period so that he could offer evidence to the Board that his risk was manageable in the community. In January 2013 the appellant commenced the Constructs course, having been transferred to HMP Perth so as to enable him to do so earlier than would have been possible at HMP Addiewell. He completed it during April 2013. In May 2013 he commenced the CARE programme. He completed it during September 2013. He then underwent assessment for progression to open conditions. He was assessed as suitable, and a place was found at HMP Castle Huntly. Supported accommodation was secured in Edinburgh where he could spend periods of home leave, and thus provide evidence that the risk he presented was manageable in the community. On 9 December 2013 the Board again reviewed his case. It welcomed the progress which had been made, but decided not to direct his immediate release. It was noted that he had incurred a further two misconduct reports during 2013. The risks which he presented were still assessed as being at a high level, and were likely to remain so until he had been tested in the community. A period at HMP Castle Huntly would provide him with an opportunity to put into practice what he had learned, and provide a staged approach to his return to living in the community. The Board suggested that he should apply for a further review in six months time. On 10 December 2013 the appellant was transferred to open conditions at HMP Castle Huntly. He began to take home leaves. In February 2014 he was returned to closed conditions at HMP Addiewell, after illicit substances were found in a locker to which he had a key. In August 2014 he was returned to open conditions at HMP Castle Huntly. Three days later he was returned to closed conditions at HMP Addiewell, after he was found to be under the influence of an illicit substance. He declined to engage with the addictions team there. Later that month he appeared in court on two historical charges of sexual abuse of children and one of rape. A case conference held in September 2014 concluded that he did not need to repeat any courses, but needed to apply what he had already learned. On 26 September 2014 the Board again reviewed his case, and decided not to direct his release. It noted that, notwithstanding his completion of all required programme work, he had not acquired the skills which he had been taught. The risk of his reoffending and causing serious harm remained too high to be managed in the community. The appellant was released from prison on 4 August 2015, on the expiry of the extension period. Discussion There can be no doubt, in the light of this history, that the appellant was provided with a real opportunity for rehabilitation. From the outset of the custodial term of his sentence, he was provided with rehabilitative courses during 2006 and 2007 which enabled him to progress to a top end facility in 2008. He nevertheless continued to be involved in violent behaviour and to abuse drugs, leading to his return to closed conditions in 2009. He was then provided with courses designed to assist him in avoiding drug and alcohol misuse, prior to his release on licence in 2010. Around four months later, however, he reoffended while under the influence of alcohol, and in consequence was recalled to custody. Following his return to custody, he continued to be involved in violent behaviour, leading to the Boards advice in December 2010 that he should be assessed for his suitability to repeat the Constructs course he had previously undertaken in 2007, and the Violence Prevention programme. In the event, however, he was transferred to another prison, following further violent conduct, before that assessment had been carried out. Although the Violence Prevention programme was not available there, it is not apparent from the documents before the court why an assessment of his suitability to repeat the Constructs course was not carried out. The appellant has not sought to adduce any evidence in relation to this matter, for example from those who were involved in the management of his sentence during that period. In the circumstances, the court cannot speculate as to whether there was or was not a good reason for his not being assessed at this time for the Constructs course. It is however clear that the appellant was not simply left in limbo: there continued to be an annual case conference to consider his management plan (including the provision of appropriate work and education), and an annual review by the Board, and he was provided with two other courses during 2011, namely the Alcohol Awareness course and the Goals course. There is no reason to doubt that those courses were appropriate for him. Any delay in assessment for the Constructs course during this period is in any event only a small part of the overall picture. Once the appellant was assessed in May 2012 as suitable to repeat the Constructs course, to be followed by the CARE programme, he was provided with places on those courses without unreasonable delay. The period between May 2012 and January 2013, when the Constructs course began, was longer than would be ideal, but the prison authorities cannot be criticised for allocating the available places in accordance with a consistent scheme of prioritisation. The reasonableness of the decision to adopt that particular scheme is not challenged in these proceedings. It was unfortunate that staff changes resulted in the postponement of the course, but an effort was then made to avoid further delay by arranging a transfer to a prison where the course was available sooner. The overall delay was not of an order which might render the appellants detention after the expiry of his custodial term arbitrary. As was said by Lord Mance and Lord Hughes in Kaiyam at para 60, article 5 does not entitle the court to characterise as arbitrary detention any case which it concludes might have been better managed: It requires that an opportunity must be afforded to the prisoner which is reasonable in all the circumstances, taking into account, among all those circumstances, his history and prognosis, the risks he presents, the competing needs of other prisoners, the resources available and the use which has been made of such rehabilitative opportunity as there has been. After completing the CARE course in September 2013, the appellant was then transferred to open conditions without any greater delay than was necessitated by the need to make the necessary arrangements. The problems which then ensued, between his transfer to open conditions in December 2013 and the final review of his case in September 2014, were entirely his own responsibility. He failed to apply what he had been taught, and instead continued to misuse illicit substances. There is no question in this case of the appellants being left in limbo without sentencing planning and without any attempt to provide him with an opportunity to rehabilitate himself. This case bears no resemblance to that of James. On the contrary, there were courses provided and completed, regular planning meetings, efforts made to find appropriate rehabilitative work, and transfers to less restrictive conditions. The problem which resulted in the appellants serving the whole of his sentence was not the failure of the prison authorities to provide appropriate courses, but his own misconduct. There is simply no question of his detention during the extension period, or at any other point during his sentence, having been arbitrary. Conclusion For these reasons, I reach the same conclusion as the Lord Ordinary and the judges of the Inner House, although their reasoning was understandably different in some respects, reflecting the development of this area of the law during the course of these proceedings. I would therefore dismiss the appeal.