Improved implementation of thread pool