Fixed infinite dequeue loop