Fix: handle uncaught exceptions