Added a while loop before calling pool.stop()