Fix bugs in the queue