Update test-set: add multhread tests. Refactoring. Thread-safety improved. Bug fixed.