Handle correctly switching between different queues.
Merge pull request #9 from ktf/master

Fix bug which did not make switching of queues working correctly