Use helper function to remove duplicate code for the ThreadPoolExecutor part
Use helper function to remove duplicate code for the ThreadPoolExecutor part