added some error handing