Fix bug with tail update after Dequeue

Experimenting with BFS uncovered a nasty bug due to the management of
the tail pointer after dequeuing operations. Fixed, and added a
(somewhat convoluted) test bit to prove it works.