added some error handling
Added some error handling