Improved exception  handling in the worker