Fixed multi-threading issue #41