Fixes in error handling