add simple thread pool and some refactoring