fix bug introduced in f315f08dc3af4879b5456a1274b143e637cac47d

closes PR 13435

Also cleaned up one more threading problem (this one was
probably innocuous, but it is hard to be sure and the
rewrite is easier to see that it isn't problematic)