Some work on error handling, mainly to catch uncaught exceptions in the worker thread, to prevent it from dying