some tweaks to error handling