Updated to thread safe the queue