Added a bit of error handling... I think it works, test conditions are out of my control