Implemented thread pooling and added tests.