Some bugs in queue implementation fixed.

And there have been more changes (I need to strengthen my commiting discipline).