Implemented multi-threading correctly