added some missing error handling