multi-threading code added