Fixed multi-threads issues