A man visiting his incarcerated son at the Cook County Jail in Chicago on Saturday was accidentally trapped inside the maximum security prison for 31 hours after a door locked behind him as he entered a visiting room.

The man was only rescued after he broke an overhead sprinkler, alerting firefighters in the Chicago Fire Department. Reportedly the locked visiting room went unchecked because no one uses it on the weekends.

"Brilliantly, he broke the sprinkler head off which alerted the fire department so they were able to identify where it was coming from and they went in and found him,'' Cara Smith, the jail's executive director, told the Chicago-Tribune: "[One he was discovered] he was incredibly, obviously, relieved and couldn't have been more gracious."

From the Chicago-Tribune:

The man, who is middle-aged, had to have a "couple of stitches" on one of his thumbs from breaking the sprinkler and was taken to Rush University Medical Center. Smith said she met with the man early Monday about 3 a.m. and he was taken back to the jail after he was treated to pick up his car, she said.

The man's son is in jail awaiting trial for a drug case and has been at Cook County Jail for thirteen months.

[Image via AP]