making torch thread-safe, part of the patch inspired by @pesky