Minor tweaks to error handling