Fix multi-threading issue