Add pthread pool. Code refactoring.