tweaked error handling