Thread-safe changes proposed by Joel Mueller