added some additional error handling