fixed some multi-threading issues