A report by the UK's chief prison inspector has highlighted concerns about the detention of vulnerable asylum seekers at Dungavel immigration removal centre (IRC) in Lanarkshire.
Her Majesty's Inspectorate of Prisons (HMIP) found problems with reporting at the centre meant some vulnerable detainees were being held despite safeguards intended to prevent this.
They included an alleged rape victim.
Detainees were also found to have been held for "very long periods".
HMIP said, however, there were "good outcomes" for detainees and described Dungavel as a "safe place".
The report follows a BBC investigation in March this year, which found that some detainees had been held at Dungavel for more than a year.
Concerns about detainee welfare and unconfirmed reports of a possible hunger strike at the centre led to a request for access from a coalition of trades union, refugee and faith groups, which the Home Office declined.
The HMIP inspection was conducted in February - before the BBC's investigation - and is the result of an unannounced visit to Dungavel.
It presents a positive image of the operation of the centre overall, saying that relations between detainees and staff were "excellent" and that staff worked to "mitigate the inevitable stresses of life in detention".
However, the report highlights two main areas of concern around the holding of vulnerable individuals and lengthy periods in detention.
Under Section 35 of the 2001 Detention Centre Rules - the legislation which governs IRCs - a report must be prepared on any person whose mental or physical health is likely worsen as a result of being held in detention.
This includes detainees who present evidence of having been tortured in their country of origin.
These so-called Rule 35 reports are then sent to the Home Office, which makes a decision on whether to release or continue to detain the person.
HMIP identified a number of issues with this process at Dungavel, including the quality of Rule 35 reports.
It said: "The quality of Rule 35 reports was variable. Some were very clear, detailed and persuasive, while others were short and lacked diagnostic findings. Two of the 10 reports we looked at had led to release, but in other compelling cases detention had been maintained."
The report highlights some cases of particular concern.
In one, documented torture survivor was held at Dungavel despite the rules stating that those with a history of torture may only be held in detention in exceptional circumstances.
In another case, a completed report read: "You may have been a victim of torture. However, it has been decided that you will remain in detention."
And in the case of one female detainee, "slow responsiveness by the Home Office" was said to have led to her being held for too long.
Two days after the woman arrive at the centre, Glasgow social services informed the Home Office that the detainee was receiving counselling following an alleged rape and that detention could cause her further trauma.
A Rule 35 report was completed which said that she was unsuitable for detention and a decision was made to release her, but she had already been transferred to another centre that day.
It took a further four days to move her back to Dungavel and eventually the care of social services, meaning that she had been held for nine days after the Home Office was first informed that she was a vulnerable detainee.
The report recommends that future reports for potentially vulnerable detainees contain what it calls "diagnostic findings" - evidence based on medical assessments - and that torture survivors or people with serious health issues should not be detained at Dungavel.
HMIP inspectors also expressed concern at the "unreasonably long" periods some were spending in detention, citing one case where an Iranian detainee had been held for two and a half years.
It was found that some cases of lengthy detention were the result of "avoidable casework delays, especially in the processing of asylum claims."
At the time of the inspection, 10 detainees had been in Dungavel for over 10 months.
The BBC's report in March found that 32 detainees had been held for over six months, while two had been held for more than a year.
Currently, the UK is the only country in the European Union which has no cap on the time someone can be detained under immigration powers and earlier this year a group of MPs called for a 28-day limit on the length of time detainees can be held in Dungavel and other centres across the UK.
Doctors and campaign groups have linked lengthy spells in detention - particularly for those with a history of torture - to mental health problems including anxiety, depression and Post-Traumatic Stress Disorder (PTSD).
In a statement, the Home Office said: "We are pleased that HMIP has found that Dungavel House is a safe place, where detainees are given the support and help they need.
"Detention and removal are essential parts of effective immigration controls, helping to ensure that those with no right to remain in the UK are returned to their home country if they will not leave voluntarily.
"It is used as a last resort and for the shortest period necessary. Decisions to detain an individual are reviewed regularly to ensure they remains justified and reasonable - and, if necessary, can be challenged through the courts. Parliament demonstrated its support for our policy when it rejected proposals to limit the length of detention during the passage of the Immigration Act last year.
"We take our responsibilities towards detainees' welfare extremely seriously. That is why the Home Secretary has commissioned an independent review of detainees' welfare to be conducted by the former prisons ombudsman Stephen Shaw. This is expected to be completed in the autumn."