slightly more correct error handling