better multi-threading logic