Added some lines at the end to release any threads waiting on the queue before program termination