added some try and catch to make sure the program doesn't crash