global refactoring, add multithreading