Moved creation of threadpool outside loop