added some try/except blocks
enclosed the whole thing in a try/catch, whatever