Refactor multithread