Fixing dequeue logic.