added some error handling