Add multi-threading pattern, but seems not thread-safe...TODO fix