Adding multi-thread support