fixed threading issue raised in #1