Fixed issues with queues.
Tweaked code to get more performance from it.