Police have apologised for their handling of the case of a man kept in custody who later died.
Alan Hay, 49, of Dalbeattie, was arrested in August 2016 and taken into custody at Loreburn Street in Dumfries.
He complained of feeling ill, but an inquiry found his symptoms were mistaken for alcohol withdrawal.
It also said “insulting and derogatory” remarks were directed at him by custody staff. Police Scotland said its high standards had not been “fully met”.
Mr Hay was arrested on 1 August and taken into custody in Dumfries.
From the outset until he appeared in court the following day he complained of feeling severe abdominal pain.
He was then taken to Barlinnie Prison where he collapsed, and died soon after at Glasgow Royal Infirmary.
The cause of death was acute peritonitis due to a perforated ulcer.
Following a fatal accident inquiry, Sheriff Linda Ruxton said several warning signs had been “overlooked or misinterpreted”.
She said his “unsettled behaviour and constant changing of position” was a sign of serious illness but had been dismissed as common behaviour in the custodial setting.
Staff had mistakenly attributed his symptoms to alcohol withdrawal and monitoring of his condition was inadequate, with cell checks “often perfunctory in nature”.
The sheriff also said record-keeping was “substandard” and the quality of care was reduced due to a “persistent attitude of disbelief and scepticism” from staff who directed “insulting and derogatory remarks” at Mr Hay.
“There are many lessons to be learned from the distressing circumstances of Alan Hay’s death,” she said in her ruling.
She added that while there were no reasonable precautions which could have prevented his death, there were steps which could have spared him a “great deal of suffering”.