fix some error handling