multyThreading and some refactoring