Fixed insidous multi-threading bug