add support for multi-threading and more performance improvements