When the United States President Barack Obama inherited the Guantanamo prison from George W Bush in January 2009, he promised to close it within a year.
However, as he prepares to leave office nearly eight years later, the prison remains open, a failure that is not only a black mark on his legacy, but may also facilitate a return under Donald Trump to some of the excesses of the Bush years.
Trump has spoken about keeping Guantanamo open, and adding to the prison's population, something that Obama repeatedly refused to do. In April, Trump said he was "gonna load it up with some bad dudes", and in August, when asked if he "might push for Americans accused of terrorism to be tried" at Guantanamo, he said that "would be fine".
On the campaign trail, Trump also supported the use of torture. In November 2015, he defended waterboarding - an ancient torture technique used by the CIA on "high-value detainees" - but he will have an uphill struggle to reinstate the use of torture.
On taking office in 2009, President Obama issued an executive order requiring all government employees, including the CIA, to conduct interrogations according to the Army Field Manual, which prohibits torture, although critics note that Appendix M of the manual allows isolation to be used, at the discretion of commanders, which could easily lead to the abuse of prisoners.
In June 2015 the US Senate codified Obama's ban, passing an amendment to the annual defence policy bill that prevents any US government employee from using torture during the interrogation of prisoners.
On torture, then, although Obama must primarily be criticised for preventing anyone responsible for torture under Bush from being held accountable in any way, his efforts to prevent torture generally constitute progress.
On Guantanamo, however, Obama's record is much more worrying, from the point of view of what Trump might want to do.
Why wasn't Guantanamo closed?
To begin with, Congress never endorsed Obama's executive order calling for the prison's closure, and politicians have persistently passed legislation designed to thwart his efforts to release prisoners, and to prevent him from bringing any prisoners to the US mainland, thereby preventing the closure of the prison camp.
Obama first met resistance in May 2009, when, in the absence of an actual plan for closing Guantanamo, Democrats joined with Republicans to vote 90 against 6 to "strip $80m earmarked for the closure of Guantanamo" from a bill to fund the wars in Afghanistan and Iraq.
With a month to go before the end of the Obama presidency, it is troubling that Guantanamo remains open - but although we must worry what Trump has planned, it must also be acknowledged that Obama should have closed the prison as he promised
That November, Attorney General Eric Holder announced that Khalid Sheikh Mohammed and four other men accused of involvement in the 9/11 attacks would be tried in federal court in New York, but when faced with criticism, in particular from the right-wing organisation Keep America Safe, the administration gave up and opted for a military commission trial instead - the much-criticised system set up under Bush, which is so full of holes that it is almost incapable of delivering anything resembling justice.
By the autumn of 2010, further Congressional restrictions regarding the release of prisoners, which involved the defence secretary having to notify Congress of any proposed prisoner release, and to certify to politicians that it was safe to do so, led to a period of nearly three years in which only five men were released from Guantanamo, even though more than half of the 174 men held at the start of this period had been approved for release - most by an inter-agency task force that Obama had set up in 2009 to review all the prisoners' cases.
Because of the restrictions, the only releases in this period were of men approved for release by the courts, or as a result of plea deals in the military commissions.
Where did it all fail?
Obama has persistently portrayed Congress as the sole obstacle to the fulfilment of his promise, even though allies, including Senator Carl Levin, the chair of the influential Senate Armed Services Committee, inserted a waiver into the legislation regarding Guantanamo to allow him to bypass Congress if he regarded it as being in the US's national security interests. This, however, was something he never did, because, to be blunt, he was unwilling to spend political capital doing so.
For reasons that have never been adequately explained, Obama also failed to prevent the Justice Department challenging every habeas corpus petition submitted by prisoners as a result of their 2008 Supreme Court victory, even in the cases of men whose release had been approved by Obama's own task force.
And even, in 2011, the appeals court in Washington DC disgracefully shut down habeas corpus for the prisoners for nakedly ideological reasons, absurdly requiring judges to treat any alleged "evidence" presented by the government as reliable.
It was only after a prison-wide hunger strike in 2013 that Obama renewed his interest in releasing prisoners and working towards the closure of Guantanamo.
Although Obama did release 178 prisoners and only 59 men are still held at Guantanamo, his failure to robustly tackle Congress on the issue throughout his presidency must be regarded as the main reason the prison will, almost certainly, remain open when he leaves office, allowing Trump to scrap Obama's executive order promising to close it, if he wishes, and possibly to add to its population.
That, again, will be easier said than done, because the law currently prevents US citizens from being sent to Guantanamo, and if Trump wants to send new foreign prisoners to Guantanamo, from the conflict with the Islamic State of Iraq and the Levant, for example, he will almost certainly find that the justification for holding prisoners at Guantanamo - the Authorization for Use of Military Force, passed in the days after the 9/11 attacks - will not be acceptable, as it only applies to al-Qaeda, the Taliban and associated forces.
With a month to go before the end of the Obama presidency, it is troubling that Guantanamo remains open. And although we must worry about what Trump has planned, it must also be acknowledged that Obama should have closed the prison as he promised he would - and could have done had he shown more conviction.
Andy Worthington is a freelance investigative journalist.
The views expressed in this article are the author's own and do not necessarily reflect Al Jazeera's editorial policy.