Works with single pass but breaks when dequeue is emptied and restarted