add uncaught exception handler, fix stack trace printing