fix crashes when running threads from the REPL