Improve multi-thread support