some changes to multi-threading