Finally fixed multi-threading